How to affect only one object out of many objects with the same name using script?
I created many instances of planet object using a prefab and I only want to affect a single instance of the planet. I deleted some code here but if I click on a planet, it should show the status of the single planet that I clicked on but status of all instances of planet shows up.
I have tried putting this. and using GetChildComponents but none of these seem to work including the .Find I'm using. Please help!
public class PlanetStatus : MonoBehaviour { private Canvas statusCanvas; private string tagName;
// Use this for initialization
void Start () {
statusCanvas = transform.Find ("Canvas").gameObject.GetComponent<Canvas> ();
tagName = "";
}
...........
void showCanvas (string tagName) {
if (tagName == "Planet") {
if (statusCanvas.enabled) {
statusCanvas.enabled = false;
} else {
statusCanvas.enabled = true;
}
}
}
}
Your answer
Follow this Question
Related Questions
Create gameobject in hierarchy on Unity refresh but before Play mode 0 Answers
Does using multiple World Space Canvases affect performance? 0 Answers
Save gameobject from imported mesh (with imported texture) as prefab/resource at runtime. 0 Answers
Saving canvas to prefab 0 Answers
What is Casting in Unity ? 1 Answer