Advertisement
CakeMeister

2D shooter arm rotation phan 3

Jul 24th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class armrotation : MonoBehaviour {
  6.  
  7.     public Player player;
  8.     public float x;
  9.    
  10.  
  11.     public Vector3 fliparm;
  12.  
  13.     // Use this for initialization
  14.     void Start () {
  15.         x = transform.localScale.x;
  16.         fliparm = transform.localScale;
  17.         player = GetComponentInParent<Player>();
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void Update () {
  22.  
  23.         Vector3 difference = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
  24.         difference.Normalize();
  25.  
  26.         float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
  27.  
  28.         if (difference.x >= 0)
  29.         {
  30.             transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
  31.             player.armright = true;
  32.         }
  33.  
  34.         else
  35.         {
  36.             transform.rotation = Quaternion.Euler(0f, 0f, rotZ+180);
  37.             player.armright = false;
  38.         }
  39.  
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement