Пример #1
0
        void FixedUpdate()
        {
            // If the user cannot control the player...
            if (canControl == false)
            {
                // Then reset the player's rotation, position, velocity and angular vel.
                myRigidbody.rotation        = Quaternion.identity;
                myRigidbody.position        = Vector3.zero;
                myRigidbody.velocity        = Vector3.zero;
                myRigidbody.angularVelocity = Vector3.zero;
            }
            else
            {
                // Figure out the rotation that the player should be facing and apply it.
                Vector3 lookRot = new Vector3(movePosition.x, 0, movePosition.y);
                transform.LookAt(transform.position + lookRot);

                // Also figure out the rotation of the player's gun and apply it.
                Vector3 gunRot = new Vector3(shootPosition.x, 0, shootPosition.y);
                gunTrans.LookAt(gunTrans.position + gunRot);

                // Apply the input force to the player.
                myRigidbody.AddForce(transform.forward * UltimateJoystick.GetDistance("Movement") * 1000.0f * accelerationSpeed * Time.deltaTime);

                // If the player's force is greater than the max speed, then normalize it.
                if (myRigidbody.velocity.magnitude > maxSpeed)
                {
                    myRigidbody.velocity = myRigidbody.velocity.normalized * maxSpeed;
                }

                // Run the CheckExitScreen function to see if the player has left the screen.
                CheckExitScreen();
            }
        }
Пример #2
0
    private void JoystickShooting(UltimateJoystick joystick)
    {
        if (PlayerController.instance == null)
        {
            return;
        }

        shootPosition = new Vector3(joystick.GetHorizontalAxis(), joystick.GetVerticalAxis(), 0);

        if (joystick.GetJoystickState())
        {
            isShoot = true;
            TryShot();
            PlayerController.instance.isBouderJoystickShoot = joystick.GetDistance() >= 0.9f;
            if (autoTarget.Count == 0)
            {
                if (PlayerController.instance.isBouderJoystickShoot)
                {
                    PlayerController.instance.FlipX = shootPosition.x < 0;
                    PlayerController.instance.SelectNonTarget(shootPosition);
                }
            }
            else
            {
                PlayerController.instance.SelectTarget(shootPosition);
            }
        }
        else
        {
#if UNITY_EDITOR
#else
            if (PlayerController.instance.currentGun == 6)
            {
                PlayerController.instance.DisableLaser();
            }
            PlayerController.instance.EndShot();
#endif
            if (isShoot)
            {
                SoundController.instance.PlaySound(soundGame.soundbulletdrop);
                isShoot = false;
            }

            if (autoTarget.Count == 0)
            {
                PlayerController.instance.SelectNonTarget(!PlayerController.instance.FlipX ? Vector2.right : Vector2.left);
            }
            else
            {
                PlayerController.instance.SelectTarget(!PlayerController.instance.FlipX ? Vector2.right : Vector2.left);
            }
        }
    }
Пример #3
0
 private void JoystickMovement(UltimateJoystick joystick)
 {
     movePosition = new Vector3(joystick.GetHorizontalAxis(), joystick.GetVerticalAxis(), 0);
     if (joystick.GetJoystickState())
     {
         PlayerController.instance.isBouderJoystickMove = joystick.GetDistance() >= 0.2f;
         if (PlayerController.instance.isBouderJoystickMove)
         {
             OnMove(movePosition);
         }
     }
     else
     {
         if (PlayerController.instance == null)
         {
             return;
         }
         StopMove();
     }
 }