// 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;
        }
        }
    }
Ejemplo n.º 2
0
 void Start()
 {
     PathFindingRequest.RequestPath(transform.position, target.position, OnPathFound);
 }
Ejemplo n.º 3
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;
        }
        }
    }