- Home /
How do I refer to the name of the game object the script is attached to?
I have clones of various objects spawning in but I need to refer to the individual objects in their scripts once they spawn in. How do I assign the names of the game objects to the string in their own scripts?
public string nameOfBlock; GameObject thisBlock;
Answer by Chimer0s · Feb 09, 2019 at 10:32 PM
You can just type gameObject in the script to reference the GameObject it's attached to. i.e.
nameOfBlock = gameObject.name;
It's that easy.
Oh, I see! It's literally called 'gameObject' I feel so dumb now haha. Thanks so much!
Your answer
Follow this Question
Related Questions
Reference an object's name in a string? 1 Answer
Click GameObject to change Color 1 Answer
Tag is not defined, when it has been manually created? 1 Answer
How can i check if GO collided with collider starting with name (string) 1 Answer
Access a String array in one script from another script 0 Answers