0

I'm creating GameObjects dynamically during runtime a game. Every of them has another name bust the same script. I'm looking for way to get to know which GameObject run a script and get this information in another script.

Objects are created here:

for (int i = 0; i < w.wHowManyWords; i++)
    {
        var obj = new GameObject();
        obj.name = w.wLevelWords[i, 0];
        elementName = obj.name;
...
    }

I'd like to get information about which object started this script:

public class ClickAction : MonoBehaviour, IPointerClickHandler
{
    private string[,] levelWords;

    public void OnPointerClick(PointerEventData eventData)
    {
        print("I am here");
    }
}
2
  • 3
    can't you just say print(gameObject.name)? Commented Nov 14, 2016 at 18:21
  • Perfect! I was looking for that! Thank you! Commented Nov 14, 2016 at 18:23

1 Answer 1

3

code11 already answered but if you want more control you can use this:

Debug.Log(gameObject.name, gameObject);

when you click on log message in console window it will highlight the object in hierarchy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.