// Use this for initialization
    void Start()
    {
        //initialize the state machine and set it to the first state
        states = MinionStates.Idle;

        enemyTrans = GameObject.FindGameObjectWithTag("BlueMinion").transform;
    }
 void ChangeState(MinionStates newState)
 {
     if (currentState == newState)
     {
         return;
     }
     currentState = newState;
     animations.ChangeState(newState);
 }
    void OnEnable()
    {
        aiPath.isStopped = true;
        hitBox.SetActive(true);

        currentState       = MinionStates.Idle;
        isInDamageMode     = false;
        needToDamageToggle = false;
        damageTimerOn      = false;
        CancelInvoke();
        timeToToggle = Random.Range(timeToToggleMin, timeToToggleMax);
        fire.SetActive(false);
    }
Exemple #4
0
 public void ChangeState(MinionStates newState)
 {
     anim.Play(stateToString[newState]);
 }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        cooldownTimer = Mathf.Clamp(0, cooldownTimer, 5);

        if (enemyTrans == null)
        {
            enemyTrans = GameObject.FindGameObjectWithTag("BlueMinion").transform;
        }

        switch (states)
        {
        case MinionStates.Idle:
        {
            Debug.Log("Minion waiting for game start");
            //count down the time for every second in game.
            cooldownTimer -= Time.deltaTime;

            if (cooldownTimer <= 0)
            {
                states = MinionStates.Wander;
            }
            break;
        }

        case MinionStates.Chase:
        {
            if (_target == null)
            {
                states = MinionStates.Wander;
                return;
            }

            transform.LookAt(enemyTrans);
            transform.Translate(Vector3.forward * 10 * Time.deltaTime);
            //the raycast will read the script of the colliding object and subtract its health

            if (Physics.Raycast(transform.position, transform.forward, out hit))
            {
                if (hit.collider.gameObject.tag == "BlueMinion")
                {
                    hit.collider.gameObject.GetComponent <MinionHealth>().health -= 5f;
                    print("BlueEnemy Detected");
                }
            }
            //  Debug.Log(states);
            break;
        }


        case MinionStates.Wander:
        {
            if (startPath == false)
            {
                startPath = true;
                PathFindingRequest.RequestPath(transform.position, target.position, OnPathFound);
            }


            var targetToAggro = CheckForAggro();
            if (targetToAggro != null)
            {
                _target = targetToAggro.GetComponent <BlueMinionMachine>();
                states  = MinionStates.Chase;
            }
            Debug.Log("Minion moving down lane");
            break;
        }
        }
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        cooldownTimer = Mathf.Clamp(0, cooldownTimer, 5);

        if (enemyTrans == null)
        {
            enemyTrans = GameObject.FindGameObjectWithTag("RedMinion").transform;
        }
        else
        {
            turretTrans = GameObject.FindGameObjectWithTag("Turret").transform;
        }
        switch (states)
        {
        case MinionStates.Idle:
        {
            Debug.Log("Minion waiting for game start");

            cooldownTimer -= Time.deltaTime;

            if (cooldownTimer <= 0)
            {
                states = MinionStates.Wander;
            }
            break;
        }

        case MinionStates.Chase:
        {
            if (_target == null)
            {
                states = MinionStates.Wander;
                return;
            }

            transform.LookAt(enemyTrans);
            transform.Translate(Vector3.forward * 10 * Time.deltaTime);
            //the raycast will read the script of the colliding object and subtract its health

            if (Physics.Raycast(transform.position, transform.forward, out hit))
            {
                if (hit.collider.gameObject.tag == "RedMinion")
                {
                    hit.collider.gameObject.GetComponent <MinionHealth>().health -= 5f;
                    print("RedEnemy Detected");
                }
            }
            //  Debug.Log(states);
            break;
        }

        case MinionStates.AttackTurret:
        {
            //if the float is lower(within range) than the distance look at the target
            if (turretDistance <= ViewDistance)
            {
                transform.LookAt(turretTrans);
            }


            break;
        }


        case MinionStates.Wander:
        {
            if (startPath == false)
            {
                startPath = true;
                PathFindingRequest.RequestPath(transform.position, target.position, OnPathFound);
            }

            var targetToAggro = CheckForAggro();
            if (targetToAggro != null)
            {
                _target = targetToAggro.GetComponent <RedMinionMachine>();
                states  = MinionStates.Chase;
            }


            //convert the enemies distance into a float
            turretDistance = Vector3.Distance(turretTrans.position, transform.position);


            //if the float is lower(within range) than the distance look at the target
            if (turretDistance <= ViewDistance)
            {
                states = MinionStates.AttackTurret;
            }


            Debug.Log("Minion moving down lane");
            break;
        }
        }
    }