So..I want my 2d Object to be able to move only between -50 & 50 z axis. What code should i put? I did if(gameobject.transform.rotation.eulerangle.z == 50){ speed = 0; } when it hits 50 it stops but i can't move back. why is that? what code should i put so it can move back and forth
try, if(gameobject.transform.rotation.eulerangle.z > 50){ gameobject.transform.rotation.eulerangle.z = 50} or show more of your code
Wouldn't a simple Mathf.Clamp(transform.rotation.eulerangle.z, -50, 50) work for this? It's been a while since I've tried clamping a euler but I'm pretty sure it would achieve the desired effect.
Code (CSharp): using UnityEngine; using System.Collections; public class playerControl_B : MonoBehaviour { public float speed; bool death; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (death == true) speed = 0; float vVal = Input.GetAxis ("PlayerOrbit_B") * speed; transform.Rotate (0, 0, vVal); That's my code ^ I've tried both and none of them work.