AI Problem Tracking Object
Hi, I am a newbie in Unity. So, I have use this simple script to make AI track an object.
move = true;
// find reference for the ball transform
GameObject ballGameObject = GameObject.Find("ball");
if (ballGameObject == null)
{
Debug.LogWarning("PlayerAI cannot find ball.");
enabled = false;
}
else
{
ballTransform = ballGameObject.transform;
}
The problem is when I use instantiate, the AI will not track to the instantiated object. I have also change the tag, but still it will return the log warning. So the question is, what do I need to do to make the AI works to instantiated object?
Answer by AtGfx · May 08, 2017 at 02:43 PM
Did you try to set the tag to "Ball" and use GameObject.FindWithTag ?
still not working. Is there any thing that I can do other than write different code?
Hmm I don't know, you have to debug ^^. $$anonymous$$aybe you can try to list all the game objects of your scene and check by hand if your game object with the correct tag is present or not. Then you can go further...
Answer by nathanlink169 · Jun 02, 2017 at 12:04 PM
Two potential issues:
-Your game object is not titled "ball" (ensure that the casing is correct).
-Your object hasn't been created when this code has been hit.