Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. void Update(){
  2. Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; // subtracting the position of the player from the mouse mous position
  3. difference.Normalize(); // normalizing the vector. meaning that all the sum of the vector will be equal to 1
  4. float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; //find the angle in degrees
  5. transform.rotation = Quaternion.Euler(0f, 0f, rotZ );
  6.  
  7. }
  8.  
  9. void Update(){
  10.  
  11. transform.Rotate(0, 0, -3.0f);
  12.  
  13. }
  14.  
  15. private int direction = 1;
  16.  
  17. void Update(){
  18. if(transform.rotation.z == 0 || transform.rotation.z == 180){
  19. direction = -direction;
  20. }
  21. transform.Rotate(0,0,-3f*direction);
  22. }
  23.  
  24. public class Turret {
  25.  
  26. [SerializeField] private float _minEulerRotation;
  27. [SerializeField] private float _maxEulerRotation;
  28.  
  29. [SerializeField] private float _rotationAmount;
  30.  
  31. private CoolDown _coolDown;
  32.  
  33. void Start(){
  34.  
  35. this._rotationAmount *= Time.fixedDeltaTime;
  36.  
  37. this.StartCoroutine(this.RotationProcess());
  38.  
  39. }
  40.  
  41. private IEnumerator RotationProcess()
  42. {
  43. while (true)
  44. {
  45. yield return this.StartCoroutine(this.RotateToMin());
  46. yield return this.StartCoroutine(this.RotateToMax());
  47. }
  48. }
  49.  
  50. private IEnumerator RotateToMin()
  51. {
  52. while(transform.rotation.eulerAngles."Axis you need" > this._minEulerRotation){
  53.  
  54. transform.Rotate("Your vector3" * this._rotationAmount);
  55.  
  56. if(this._coolDown.IsActive)
  57. {
  58. yield return this._coolDown.Delay;
  59. }
  60.  
  61. yield return null;
  62. }
  63.  
  64. transform.rotation = Quaternion.Euler("Your vector3" * this._minEulerRotation);
  65. }
  66.  
  67. private IEnumerator RotateToMax()
  68. {
  69. while(transform.rotation.eulerAngles."Axis you need" < this._maxEulerRotation){
  70.  
  71. transform.Rotate("Your vector3" * this._rotationAmount);
  72.  
  73. if(this._coolDown.IsActive)
  74. {
  75. yield return this._coolDown.Delay;
  76. }
  77.  
  78. yield return null;
  79. }
  80.  
  81. transform.rotation = Quaternion.Euler("Your vector3" * this._maxEulerRotation);
  82. }
  83.  
  84. public void Shoot()
  85. {
  86. ...... some cooldown stuff
  87. this._coolDown.StartCountdown();
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement