Boss won't track player movement
I'm making a game where the boss is supposed to come in at one point. Everything works fine save for the player tracking. I added a public Transform field to the boss' movement script and am trying to get the players transform by linking it in Unity, however when I put it in the Update function it returns the initial transform of my player no matter where I move him. Here is the code:
public Transform player;
public float fireRate, speed;
Rigidbody2D rb;
void Update ()
{
float dy = transform.position.y - player.transform.position.y;
Debug.Log(transform.position.y + ", " + player.position.y);
if (dy > 0) { rb.velocity = new Vector2(0f, speed); }
else if (dy < 0) { rb.velocity = new Vector2(0f, -speed); }
}
And a screenshot of the editor view:
In the first and second one you can see that the Debug.Log() output is showing the same second number (the players position on the y axis) even though he is in different places, while the first number (the cow's position on the y axis) has changed. Is there any way I can continuously track the players transform?
Answer by Fish97 · Feb 06, 2018 at 04:09 PM
I linked the prefab in the editor when I should have linked the object in the scene. Doing this fixed the problem.
Answer by JohnKlein94 · May 03 at 02:36 PM
I wonder if the apps that track your cell phone work the same way? I read the full article on this, but the insides are interesting.