Hey Guys,
Right now i have code for object restart when its reach certain position. But this code works only from Negative “X” to Positive “X” position. How can i make it work in both sides?
public class ResetPosition : MonoBehaviour
{
public int maxXPostion;
private Vector3 initialPos;
private Quaternion initialRotation;
void Start()
{
initialPos = transform.position;
initialRotation = transform.rotation;
}
void Update()
{
transform.Translate(Vector3.zero * Time.deltaTime);
if (gameObject.transform.position.x >= maxXPostion)
{
transform.rotation = initialRotation;
transform.position = initialPos;
}
}
}
i understand that i need to add:
if (gameObject.transform.position.x <= maxXPostion)
To existing code. How can i add it correctly so it actually work?