Example #1
0
 void Start()
 {
     Random.InitState((int)System.DateTime.Now.Ticks);
     agent       = GetComponent <NavMeshAgent>();
     audioSource = GetComponent <AudioSource>();
     sensingComp = GetComponent <PawnSensingComponent>();
     PawnSensingComponent.OnSeePawn   += OnSeePawnHandler;
     PawnSensingComponent.OnHearNoise += OnHearNoise;
     state = new PatrollingState();
     state.Enter(this);
 }
Example #2
0
    void Update()
    {
        IGuardState newState = state.Update();

        if (newState != null)
        {
            state.Exit();
            state = newState;
            state.Enter(this);
        }
    }
Example #3
0
    private void OnHearNoise(GameObject instigator, float loudness, Vector3 noisePosition)
    {
        Debug.Log(gameObject.name + " heard a sound at position " + noisePosition);
        IGuardState newState = state.OnHearNoise(instigator, loudness, noisePosition);

        if (newState != null)
        {
            state.Exit();
            state = newState;
            state.Enter(this);
        }
    }
Example #4
0
    private void OnSeePawnHandler(GameObject gameObject)
    {
        // Debug.Log("Sensed: " + gameObject.name);
        IGuardState newState = state.OnSeePawnHandler(gameObject);

        if (newState != null)
        {
            state.Exit();
            state = newState;
            state.Enter(this);
        }
    }
Example #5
0
    void Start()
    {
        //Start with patrolling
        currentState = guardPatrolState;
        target       = GameObject.FindWithTag("Player").GetComponent <Transform> ();
        playerLastPosition.position = new Vector3(target.position.x, target.position.y, target.position.z);
        normalSpeed = agent.speed;
        pursueSpeed = 3 * normalSpeed;
        searchSpeed = normalSpeed;        // / 2;

        //We'll use this in search mode, later.
        searchOffset     = new Vector3[4];
        searchOffset [0] = new Vector3(3f, 0f, 3f);
        searchOffset [1] = new Vector3(-3f, 0f, -3f);
        searchOffset [2] = new Vector3(3f, 0f, -3f);
        searchOffset [3] = new Vector3(-3f, 0f, 3f);
    }