コード例 #1
0
ファイル: ChaseState.cs プロジェクト: cadenkesey/lilith
    /// <summary>
    /// Called when the enemy updates its pathfinding
    /// Sets a random amount of time before the enemy should update its destination again
    /// </summary>
    /// <param name="destination">The new target for the enemy to chase</param>
    private void SetDestination(Vector3 destination)
    {
        if (!FairyCharacter.FiredLastTurn && FairyOperations.chanceToFire(FairyCharacter.transform, FairyCharacter.Player.transform))
        {
            Fsm.EnterState(FsmStateType.Attack);
        }
        else
        {
            _timeSinceLastUpdate           = 0.0f;
            _timeBetweenDestinationUpdates = Random.Range(0.5f, 2.0f);

            _pathToTarget = new NavMeshPath();
            Vector3 height = new Vector3(0, FairyCharacter.transform.position.y - FairyCharacter.GroundCheck.transform.position.y, 0);
            NavMesh.CalculatePath(FairyCharacter.transform.position - height, destination, NavMesh.AllAreas, _pathToTarget);

            _pathCorners = FairyOperations.CheckArrayForDuplicates(_pathToTarget.corners, FairyCharacter.GroundCheck.transform.position).ToArray();

            _cornerIndex = 0;

            FairyCharacter.FiredLastTurn = false;
        }
    }