Exemplo n.º 1
0
    // We have returned to where we were previously patrolling
    public void OnArriveAtPatrolPoint()
    {
        // Continue patrolling
        State_Patrol state = new State_Patrol(this);

        state.SetAnimator(anim);
        state.SetPatrolPoints(checkpoints, ticksToReach);
        state.SetNavAgent(navAgent);
        state.currentCheckpoint = lastCheckpoint;

        stateMachine.SetState(state);
    }
Exemplo n.º 2
0
    public float attackRange    = 1.2f; // How far ahead we can attack

    // Start is called before the first frame update
    new void Start()
    {
        base.Start();
        // Get references
        anim = GetComponent <Animator>();
        if (anim == null)
        {
            Debug.Log("Animator could not be found");
        }
        visionRange = GetComponent <ConeCollider>();
        if (visionRange == null)
        {
            Debug.Log("Could not find cone collider");
        }
        attackCollider = GetComponent <CapsuleCollider>();
        if (attackCollider == null)
        {
            Debug.Log("Could not find capsule collider");
        }
        navAgent = GetComponent <NavMeshAgent>();
        if (navAgent == null)
        {
            Debug.Log("Could not find nav mesh agent");
        }
        // Set the attack capsule's range
        attackCollider.radius    = attackRange;
        attackCollider.isTrigger = true;
        // Currently not attacking
        attackCollider.enabled = false;
        visionRange.enabled    = true;

        // Init list of checkpoints
        checkpoints  = new List <Vector3>();
        ticksToReach = new List <int>();
        // Get the list of checkpoints
        if (transform.Find("Movepoints") != null)
        {
            Transform movingPoints = transform.Find("Movepoints").gameObject.transform;
            int       numChildren  = movingPoints.childCount;
            for (int i = 0; i < numChildren; ++i)
            {
                // Get each checkpoint
                GameObject goalPoint = movingPoints.GetChild(i).gameObject;
                Checkpoint cp        = goalPoint.GetComponent(typeof(Checkpoint)) as Checkpoint;
                if (cp != null)
                {
                    checkpoints.Add(goalPoint.transform.position);
                    ticksToReach.Add(cp.GetMoveTime());
                }
            }
        }

        // Init state machine
        stateMachine = new FSM();
        State_Patrol state = new State_Patrol(this);

        state.SetAnimator(anim);
        state.SetNavAgent(navAgent);
        state.SetPatrolPoints(checkpoints, ticksToReach);
        state.currentCheckpoint = -1;

        stateMachine.SetState(state);
    }