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