- Home /
Vector3.Distance Not Working in 2D game
So I am trying to return the distance between two GameObjects with the normal float dist = Vector3.Distance(enemy.transform.position, transform.position); However when I debug it is not updating the position each frame despite being in the Update Method. (Printing the same distance each frame despite the enemy moving)
I think the issue lies in the fact that I am making a 2d game possibly? I have checked and they are on the same order layer and sorting layer. Any other suggestions? I have tried everything I can possibly think of! I am thinking of remaking the game, I have never encountered this problem before!
Answer by AmatuerProgrammer · Nov 28, 2017 at 06:00 AM
Solution: I just realized what the solution was after posting the question. I dragged and dropped the prefab into the public variable. Silly mistake. Don't be lazy! hard code everything!
You could just drag and drop the object from the hierarchy ins$$anonymous$$d of hard coding it.
Hard coding things should be avoided unless 100% required.
I'm glad you found a solution though! :)
Am I missing something? Sounds to me like they did drag and drop; they just dragged and dropped the wrong thing. I see no suggestion of hard coding here.
He said "Don't be lazy! Hard code everything!". I'm simply advising against doing that lol.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how can i use spot light in canvas 2d 0 Answers
Spikes for a platformer game 1 Answer
2D rigidbody top down movement problem 3 Answers