//Attacks with the equipped gun
    public bool Shoot()
    {
        if (EquippedGun != null)
        {
            return(EquippedGun.Shoot());
        }

        return(false);
    }
Пример #2
0
    void Update()
    {
        //topdown behaviour
        if (PlayerBehaviour == Type.TopDown)
        {
            //Move Input
            if (InputDirection == DirectionType.Global)
            {
                moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
            }
            else
            if (InputDirection == DirectionType.Camera)
            {
                moveDirection        = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
                cameraBasedDirection = cam.transform.TransformDirection(moveDirection);
                moveDirection        = new Vector3(cameraBasedDirection.x, moveDirection.y, cameraBasedDirection.z);
            }


            //Aim Input
            float distance;
            Plane aimPlane = new Plane(Vector3.up, Vector3.zero);
            Ray   ray      = cam.ScreenPointToRay(Input.mousePosition);
            if (aimPlane.Raycast(ray, out distance))
            {
                Vector3 hitPoint = ray.origin + ray.direction * distance;
                Debug.DrawLine(cam.transform.position, hitPoint);
                transform.LookAt(new Vector3(hitPoint.x, transform.position.y, hitPoint.z));
            }
        }

        //firstperson behaviour
        if (PlayerBehaviour == Type.FirstPerson)
        {
            EquippedGun.transform.forward = Camera.main.transform.forward;
            //EquippedGun.transform.LookAt(Camera.main.transform.forward * 1000f);
            //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //RaycastHit hit;
            //if (Physics.Raycast(ray, out hit, Mathf.Infinity, MaskToIgnore))
            //{
            //    print(":)");
            //    Debug.DrawLine(ray.origin, hit.point);
            //    EquippedGun.transform.LookAt(hit.point);
            //}
        }

        //Shoot Input
        if (Input.GetKeyDown(shootInput) && EquippedGun)
        {
            EquippedGun.Shoot();
        }

        if (moveDirection == Vector3.zero)
        {
            IsMoving = false;
        }
        else
        {
            IsMoving = true;
        }
    }