Exemplo n.º 1
0
    protected override void Awake()
    {
        base.Awake();
        OnDeath += onDeath;

        navAgent      = GetComponent <NavMeshAgent>();
        stackOfStates = GetComponent <StackFSM>();

        if (PotentialStates.Length > 0)
        {
            State patrol = PotentialStates.FirstOrDefault(x => x.StateName == StateNames.PatrolState);
            State idle   = PotentialStates.FirstOrDefault(x => x.StateName == StateNames.IdleState);
            if (patrol)
            {
                stackOfStates.PushState(patrol);
            }
            else if (idle)
            {
                stackOfStates.PushState(idle);
            }
        }

        GetPlayer();

        //TODO when speed changes also set the navAgentSpeed
        navAgent.speed = Speed;
    }
 public override void OnUpdate(ref StackFSM stackStates)
 {
     if (stackStates.aiBase.LineSightToPlayer())
     {
         State follow = stackStates.aiBase.PotentialStates.FirstOrDefault(x => x.StateName == StateNames.FollowState);
         if (follow)
         {
             stackStates.PushState(follow);
         }
     }
 }
Exemplo n.º 3
0
    protected override void Update()
    {
        base.Update();

        if (PotentialStates.Length > 0 && stackOfStates.GetCurrentState() == null)
        {
            State idle = PotentialStates.FirstOrDefault(x => x.StateName == StateNames.IdleState);
            if (idle)
            {
                stackOfStates.PushState(idle);
            }
        }

        //audio queue
        if (!CharacterAudio)
        {
            return;
        }

        var AiStateAudio = Audio.FirstOrDefault(x => x.StateName == stackOfStates.GetCurrentState().StateName);

        if (AiStateAudio.Clips != null && AiStateAudio.Clips.Length > 0)
        {
            if (nextAudioQueueTime <= 0.0f)
            {
                nextAudioQueueTime = Random.Range(AiStateAudio.MinQueueTime, AiStateAudio.MaxQueueTime);
            }

            if (audioQueueTimer >= nextAudioQueueTime && !CharacterAudio.isPlaying)
            {
                //pick random audio clip
                int audioClipIndex = Random.Range(0, AiStateAudio.Clips.Length);
                CharacterAudio.clip = AiStateAudio.Clips[audioClipIndex];
                CharacterAudio.Play();
                nextAudioQueueTime = 0.0f;
                audioQueueTimer    = 0.0f;
            }
            audioQueueTimer += Time.deltaTime;
        }
    }