Exemple #1
0
        int IComparer.Compare(object xObj, object yObj)
        {
            var x = (GameObject)xObj;
            var y = (GameObject)yObj;

            float xDist = _parent.DistanceTo(x);
            float yDist = _parent.DistanceTo(y);

            if (xDist > yDist)
            {
                return(1);
            }
            else if (yDist > xDist)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        GameObject nearestEnemy = _positioning.FindNearestTagged(EnemyTag);

        if (nearestEnemy == null)
        {
            return;
        }

        bool isMoving = _navAgent.velocity.magnitude > 0.1f;

        if (_positioning.DistanceTo(nearestEnemy) < Range &&
            (Time.time - TimeOfLastShot) > CooldownTime &&
            !isMoving)
        {
            ShootEntity(nearestEnemy);
            TimeOfLastShot = Time.time;
            DirOfLastShot  = nearestEnemy.transform.position - this.transform.position;
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        var nearestTargets = _positioning.FindAllTaggedByDistanceInRange(_hit.EnemyTag, DetectionRange);

        if (nearestTargets.Length == 0)
        {
            // No one in range
            _state = State.Idle;
        }
        else
        {
            var nearest = nearestTargets[0];

            // Move towards nearest
            _state = State.Targetting;
            _navAgent.SetDestination(nearest.transform.position);

            // Hit nearest if in range
            if (_positioning.DistanceTo(nearest) <= _hit.Range)
            {
                _animator.SetTrigger("startAttack");
            }
        }
    }