예제 #1
0
    void RotateWeapon()
    {
        var pos   = Camera.main.WorldToScreenPoint(transform.position);
        var dir   = Input.mousePosition - pos;
        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        transform.localRotation = Quaternion.AngleAxis(angle, Vector3.forward);

        if (Mathf.Abs(angle) <= 90 && gunFlipped)
        {
            flipper.flipGun();
            gunFlipped = !gunFlipped;
        }
        else if (Mathf.Abs(angle) > 90 && !gunFlipped)
        {
            flipper.flipGun();
            gunFlipped = !gunFlipped;
        }
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        flipper = this.transform.Find("Gun").GetComponent <GunFlipper> ();
        var dir   = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
        var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        if (Mathf.Abs(angle) < 90)
        {
            gunFlipped = false;
        }
        else
        {
            flipper.flipGun();
            gunFlipped = true;
        }
    }