Question by
Dan903c21 · Feb 16, 2016 at 10:00 PM ·
c#unity 5scripting problem
How to check if a player has passed a certain position??
I am trying to check if player is at 0,0,0 and if he is, move whatever direction is associated with the keys, if he has not hit 0,0,0, go there first
public float speed = 5.0f; public Transform snapLeft; public Transform snapRight;
void Update()
{
if (Input.GetKey(KeyCode.A) && transform.position = 0 ) {
if (gameObject.tag == "Player") {
transform.position = snapLeft.transform.position;
}
}
else
{
transform.position = Vector3.zero;
}
if (Input.GetKey(KeyCode.D) && transform.position = 0) {
if (gameObject.tag == "Player") {
transform.position = snapRight.transform.position;
}
}
else
{
transform.position = Vector3.zero;
}
}
}
Comment
Answer by bcaloe · Feb 18, 2016 at 04:52 PM
I can see that you are trying to set transform.position to Vector3.zero. I would advise that you also check to see if transform.position is equal to the zero vector as you assigned, not 0.
Also, did you forget another '=' in your if statement?
Your answer
Follow this Question
Related Questions
Adding a Highscore to game 1 Answer
how do i rotate an object? C# 1 Answer
Collision Detection Not Working (Unity 5.2.3) 5 Answers
Mathf.Abs always returns 0 0 Answers
How do i put "Wasted!" after respawn? 0 Answers