示例#1
0
    // Update is called once per frame
    void Update()
    {
        verticleMovement   = Input.GetAxis("Vertical");
        horizontalMovement = Input.GetAxis("Horizontal");

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, 100f, LayerMask.GetMask("Ground")))
        {
            Firing.RotateHead(hit.point);
        }

        Firing.SetIsShooting(Input.GetMouseButton(0));
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        FindClosestPlayer(); //For multiplayer will have to check for closets player

        stateMachine.Update();

        if (CanMove)
            Move();

        Vector3 headDirection = Firing.GetHeadDirection();
        Vector3 pos = transform.position;

        if (!CheckShot(pos, headDirection * MaxVisionDistance, 0, MaxVisionDistance))
        {
            Firing.SetIsShooting(false);
            Vector3 playerPos = TargetedPlayer.transform.position;
            Vector3 direction = playerPos - pos;

            //if can see player with direct line
            bool canSeePlayer = Physics.Raycast(pos, direction, out RaycastHit objectHit, MaxVisionDistance)
                && objectHit.collider.CompareTag("Player");

            if (canSeePlayer)
            { //move head towards player
                Firing.RotateHead(playerPos);
            }
            else
            {
                if(FindShot(direction))
                    Firing.RotateHead(ShootDirection);
            }
        }
        else
        {
            Firing.SetIsShooting(true);
        }
    }