- Home /
The question is answered, right answer was accepted
C# the position of the object
Hey guys,
I need to know the position of a child to the parent position. I have a script that uses transform.translate so colliders don't work anymore. it needs to stop at -5.5 and 5.5 so I thought an if statement. public class SideMove : MonoBehaviour { public float amountMove = 0.05f; void Update () { if(Input.GetButtonDown("Left")) { if(position <= -5.5) { //don't go further } else{ Vector3 position = transform.position; position.x -= amountMove; transform.position = position; } if(Input.GetButtonDown("Right")) { if(position >= 5.5) { //don't go further } else{ Vector3 position = transform.position; position.x += amountMove; transform.position = position; } } } }
sorry if the "{}" are messed up, I tried to fix it. Anyway how do I set the current position so I can use it in a if statement?
sorry for the bad english
Thank you
Answer by moha · Jun 07, 2013 at 02:43 PM
use transform.localPosition to get the the object position in its parent space.
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
What the heck is wrong with this script?! 1 Answer
If gameobject moves do this 1 Answer
Opening a door/ using a teleporter with keypress when in it's radius 0 Answers