2020년 4월 1일 수요일

(Unity personal problem experience). changing color of an object in script works, but NOT work if the object has rigidbody component

Unity 2019.3.4f1 personal



I've made a script for changing color of an object.
GetComponent<Renderer>().material.color
It works very well at first, but doesn't work any more after I've added 'rigidbody' component to the object.
I don't know why it happens.
 upper image shows the cube has rigidbody component and not changed its color.




upper image shows the cube has changed its color after its rigidbody component removed.





 Suddenly, I noticed that it's a child of prefab.
In prefab viewer(?), I've added rigidbody component and uncheck 'gravity'
Now, it works.
The cube has changed its color even if it owns rigidbody component.

댓글 없음:

댓글 쓰기