예제 #1
0
        private void updateAngle()
        {
            // Angle of mouse
            Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.GetChild(0).position);
            float   x         = Input.mousePosition.x - screenPos.x;
            float   y         = Input.mousePosition.y - screenPos.y;

            mouseAngle = Game.transformAngle(Mathf.Atan2(y, x));

            // Angle of movement
            astroAngle = Game.transformAngle(Mathf.Atan2(yVel, xVel));
            if ((astroAngle > 90) && (astroAngle < 270))
            {
                astroAngle = astroAngle - 180;
            }

            // Angle of gun
            gunAngle = mouseAngle - astroAngle;
            gunAngle = gunAngle >= 0 ? gunAngle : gunAngle + 360;

            // Transform sprites
            if ((gunAngle <= 90) || (gunAngle >= 270))
            {
                transform.localRotation             = Quaternion.Euler(0, 0, astroAngle);
                transform.GetChild(0).localRotation = Quaternion.Euler(0, 0, gunAngle);
            }
            else
            {
                transform.localRotation             = Quaternion.Euler(0, 180, 360 - astroAngle);
                transform.GetChild(0).localRotation = Quaternion.Euler(0, 0, 180 - gunAngle);
            }
        }