Having problems with setting transform.position
It's not that trying to change the transform.position doesn't work but more that the way what I'm using it in is getting in the way.
Basically I'm wanting to create a simple script where a object will dash across the room once being moved to a certain Transform object. I placed this dash script in a enum as it's going to be a state for a enemy though the main problem is that the enum updates every frame so when i try and change the transform.position of my object to the Transform object.position, it keeps doing it every frame and so it never moves.
This is the script i am using for it:
as you can see in the else if statement, I'm changing the transform.position to a Transform object and then wanting to change the velocity but again... since it's updating the enum every frame then i can't do that.
So i was wondering if someone would be able to give me a idea on how to do this? As i want the position to be changed at that moment but i don't want it to keep updating it, just once.
Answer by brazmogu · Jan 12, 2016 at 01:02 AM
Set a flag when the dash starts, and when the else is reached you set the flag to false. Then you put all this code where the timer is decreased and the trigger is set, and the whole movement is done, inside an if that's conditional to the dashing flag. This way your code will only run while the flag is true, and will stop running when the timer goes to 0.
Your answer
Follow this Question
Related Questions
Collition Coding not working 1 Answer
Moving moving Object with left/right arrow keys in a circular direction 3 Answers
Photon Multiplayer : position of client player is not getting synchronized. 0 Answers
Destroying 2D terrain at runtime 0 Answers
What is the most effective way to structure Card Effects in a Single Player game? 1 Answer