The old Unity docs have some examples. And the Unity Answers site is generally a better place to look for such things. But...
Basically, you need to reference the other gameobject and use GetComponent<YourScript>()
So, in the script your working on, you need to declare a public variable that you can assign in the inspector, or you need to use GameObject.Find("OtherGameObjectByName");
If you look at this setup, you can see two gameobjects with each with there own component/script attached. I am using this to illustrate the following code.
The 'ControlObject.cs' attached to 'GameObjectController'.
public class ControlObject : MonoBehaviour {
// There is a better place for this, other than the Start method.
// but I'm lazy.
void Start () {
// This will look for a specific game object.
GameObject mygo = GameObject.Find("GameObjectOther");
// if that game object is found...
if(mygo){
// you can access any of its components.
DynamicObject otherguy = mygo.GetComponent<DynamicObject>();
//do stuffNow you can modify public properties or call methods
otherguy.scoreCount++;
}
}
}
The 'DynamicObject.cs' attached to 'GameObjectOther'.
public class DynamicObject : MonoBehaviour {
//make sure you have a public propertey
public int scoreCount = 0;
//
void Update () {
//Do something with scoreCount.
}
}
