Beispiel #1
0
    void RotatePlayer()
    {
        //Check whether input are coming from keyboard or touch
        if (lookInput.magnitude != 0)
        {
            lookDirection = lookInput;
        }
        else
        {
            lookDirection = new Vector3(Input.GetAxisRaw("HorizontalLook"), 0, Input.GetAxisRaw("VerticalLook"));
        }

        //Rotate player
        if (lookDirection.magnitude != 0)
        {
            targetRotation = Quaternion.LookRotation(lookDirection);
            targetRotation = Quaternion.Inverse(targetRotation);
            //Debug.Log(targetRotation);
            //Debug.Log(targetRotation.eulerAngles);

            //Below used for smoother rotation
            //transform.eulerAngles = Vector3.forward * Mathf.MoveTowardsAngle(transform.eulerAngles.z, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);

            transform.eulerAngles = Vector3.forward * targetRotation.eulerAngles.y;

            //and shoot if using joystick
            if (lookInput.magnitude != 0)
            {
                projectileLauncher.Shoot();
            }
        }

        //Shoot when spacebar is pressed, Used only when testing on PC
        if (Input.GetKey("space"))
        {
            projectileLauncher.Shoot();
        }
    }
 public void ShootAfterAnimation()//this function will be called from the attack animation clip (animation event)
 {
     print("Shoot");
     projectileLauncher.Shoot();
     animator.SetBool("isShooting", false);
 }
Beispiel #3
0
 void Update()
 {
     gun.Shoot(player.transform.position - gameObject.transform.position);
 }