Can I compare a Transform variable (x, y, z) against float variables?
I am trying to create a "Return to spawn" C# script but I am strugling.
On start, I set a Transform variable to the gameObject.transform and I set three float variables to the game objects x, y and z starting values.
I want to set a variable to the distance from the object to their spawn point so they will stop moving once they are close and I know that the following can work:
distToSpawn = Vector3.Distance(myObject.position, transform.position);
but I want to use the x, y, and z float values I set at the start and I am not sure how. I do also want to compare the current object transform to the variables, is it possible to set a transform manually using the code so I can set them to the variable values?
Answer by TreyH · Feb 13, 2016 at 03:07 AM
Just keep track of the start point?
public Vector3 startPoint;
void Awake()
{
startPoint = transform.position;
}
void Update()
{
float distToSpawn = (startPoint - transform.position).magnitude;
}
Your answer
Follow this Question
Related Questions
Is there a transform method equivalent to assigning euler angle offsets? 1 Answer
Make object move back and forth 2 Answers
Transform.find problem 1 Answer
How to call a function every second ? 1 Answer
Can’t keep the position 0 Answers