Without creating a new gameobject and without specifying name of gameobject That already exist
something like
ClassAnother nameofTheInstance = this.gameobject.GetComponent(ClassAnother);
Without creating a new gameobject and without specifying name of gameobject That already exist
something like
ClassAnother nameofTheInstance = this.gameobject.GetComponent(ClassAnother);
adding another script to an object doesn’t make sense. You can just call the script or it’s functions by:
ScriptName other1;
Start() {
other1 = GetComponent<ScriptName>();
}
Update() {
if (other1.goldCoins == 17) { other1.goldCoins = 99; }
}
//short for ScriptName.GetComponent<ScriptName>().goldCoins;
Unless you’re creating a new object, and need to add the script, then:
createdGameObject.AddComponent<ScriptName>();