Beispiel #1
0
    private void DoChasingState()
    {
        // If player is outside of a certain distance, enters waiting state
        // Else chases after player and shoots them
        if (Vector3.Distance(transform.position, player.position) > distanceToChase)
        {
            state = EnemyState.Waiting;
        }
        else
        {
            // Chase the player
            // Aim the turret toward the player
            // Shoot bullet at the player
            shooting.TankAim(player.position);
            shooting.TankShoot();

            if (Vector3.Distance(transform.position, player.position) > distanceToChase / 2)
            {
                navMeshAgent.destination = player.position;
            }
            else
            {
                navMeshAgent.destination = transform.position;
            }
        }
    }
        void FixedUpdate()
        {
            // Store a reference to our input
            var moveAxis = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));

            movement.MoveTank(moveAxis);

            // All of our turret rotation script here
            var        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo; // Defining the raycast hit information

            // Projecting the actual raycast and outputting information on what we hit
            if (Physics.Raycast(ray, out hitInfo))
            {
                shooting.TankAim(hitInfo.point);
            }

            if (Input.GetMouseButton(0))
            {
                shooting.TankShoot();
            }
        }