- Home /
Question by
user-12151 (google) · Apr 30, 2011 at 04:04 PM ·
gameobjectoncollisionenter
Change variable of other game object onCollisonEnter - C#.
I've tried searching but haven't quite found anything that has answered my question.
Basically, I have a cube with an onCollisionEnter method - I then want this method to say that onCollisionEnter, change the movespeed (public float) of the game object "Character" to X value. If anyone could point me in the right direction it would be much appreciated.
Comment
Best Answer
Answer by DaveA · Apr 30, 2011 at 05:12 PM
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Components.htmland http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
ex
GameObject go = GameObject.Find("Character");
MyScript sc = (MyScript)go.GetComponent(typeof(MyScript));
sc.movespeed = X;
Your answer
![](https://koobas.hobune.stream/wayback/20220613130516im_/https://answers.unity.com/themes/thub/images/avi.jpg)