I put a script component, with a proprietary life, how I can obtain and modify the initial value from another object that collided with it?
Thank you very much.
I put a script component, with a proprietary life, how I can obtain and modify the initial value from another object that collided with it?
Thank you very much.
I’m not sure I understand your question, but I think you’re meaning to ask how do I, from a script attached to gameObject A modify a variable in a script on component B when B collides with A?
If B has a rigidbody, when upon collision the OnCollisionEnter function will be called.
function OnCollisionEnter( enter : Collider ){
if( enter.gameObject == (gameObject_B)//you could also compare tags, or some other property to identify B
enter.gameObject.GetComponent( name_of_the_script_you're_accesing ).name_of_the_variable_;
}
}
What you could do this in the object that hits the other object:
function OnCollisionEnter(coll : Collider) {
if (coll.gameObject.GetComponent(NameOfOtherScript) != null)
coll.gameObject.GetComponent(NameOfOtherScript).YourProperty;
}