Hi all,
I have a gameobject called plane and I’ve got a script that instantiates 10 clones, they get a number added to the end of them so they all have a unique gameobject name, so I end up with 11 gameobjects which are : plane ( original ) and the clones are named plane0, plane1 etc.
I have a script called playerscript attached to plane and all the plane clones.
I have another gameobject called Tower with a script called Controller attached to it.
What I want to do is, when I click on a plane I want the variable “idtext” ( which is in the Controller script ) to contain the gameobject name of the object I just clicked on.
What actually happens is if I click on the original plane idtext does equal the name “plane” as it should BUT when I click on a clone idtext doesn’t equal anything.
The debug.log shows the proper gameobject name in the console if I click on a clone but this just isn’t getting transferred to the idtext variable for some reason.
Each clone has a Box collider & a Rigidbody
Note : I have dragged gameobject Tower to Target in the inspector.
public Transform target;
void OnMouseDown(){
// this object was clicked - do something
Controller targetScript = target.GetComponent<Controller>();
a = gameObject.name;
targetScript.idtext = gameObject.name ; // this works with original but not a clone
Debug.Log (" plane clicked is " + a);
}
Any help is appreciated - thanks.