Esempio n. 1
0
    private void Update()
    {
        _attackCooldown -= Time.deltaTime;

        ManageDelayedAttacks();

        if (AttackIsReady())
        {
            if (Target != null)
            {
                if (!TargetHelper.TargetIsInRange(gameObject, Target, AttackRange))
                {
                    Target = null;
                }
            }

            if (Target == null)
            {
                Target = TargetHelper.GetNearestTargetInRange(gameObject, AttackRange);
            }

            if (Target != null)
            {
                Attack();
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    private void Update()
    {
        if (_target != null)
        {
            var newRotation = Quaternion.LookRotation(_target.transform.position - transform.position);
            newRotation.x      = 0.0f;
            newRotation.z      = 0.0f;
            transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 8);
        }

        if (_target != null)
        {
            if (!TargetHelper.TargetIsInRange(gameObject, _target, TargetSeekRange))
            {
                _target = null;
            }
        }

        if (_target == null)
        {
            _target = TargetHelper.GetNearestTargetInRange(gameObject, TargetSeekRange);
        }
    }