Advertisement
Guest User

Limit rotation

a guest
Feb 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class rotate : MonoBehaviour {
  6.  
  7. public float rotSpeed = 2;
  8. public float rotRange = 90;
  9. public float currentRot;
  10.  
  11.  
  12. void Update ()
  13. {
  14. //Input for rotation
  15. float rotDir = Input.GetAxis("Horizontal") *rotSpeed;
  16. currentRot = currentRot +rotDir;
  17.  
  18. // Limitation with clamp
  19. currentRot = Mathf.Clamp(currentRot, -rotRange, rotRange);
  20.  
  21. //rotate dat thing
  22. if(currentRot < rotRange && currentRot > -rotRange)
  23. transform.Rotate(transform.forward, +rotDir);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement