コード例 #1
0
        public override void Update()
        {
            if (GameControl.IsGameOver() || destroyed || IsStunned())
            {
                return;
            }

            //get player as target
            target = GameControl.GetPlayer();
            if (target != null && !target.thisObj.activeInHierarchy)
            {
                target = null;
            }

            //reduce the attack cooldown
            currentCD        -= Time.deltaTime;
            contactCurrentCD -= Time.deltaTime;

            //base.Update();

            //if shootPeriodically, then shoot
            if (shootPeriodically)
            {
                ShootTarget();
            }

            //if there's not target, reset the turret to origin
            if (target == null)
            {
                ResetTurret();
                return;
            }

            //calculate the target dist, this is for later use
            float targetDist = Vector3.Distance(thisT.position, target.thisT.position);

            //now depend on the unit behaviour, act accordingly
            if (behaviour == _Behaviour.Aggressive)
            {
                EngageHostile(targetDist);                      //engage the target
            }
            else if (behaviour == _Behaviour.Aggressive_Trigger)
            {
                //if target is close enough to trigger a respond, set behaviour to aggressive
                if (Vector3.Distance(thisT.position, target.thisT.position) <= aggroRange)
                {
                    behaviour = _Behaviour.Aggressive;
                }
            }
            else if (behaviour == _Behaviour.StandGuard)
            {
                if (guardTriggered)                     //if the unit is aggro'ed
                {
                    EngageHostile(targetDist);          //engage the target

                    //this line is irrelevant atm since anchor to point is not in used
                    //if(anchorToPoint) dist=Vector3.Distance(anchorPoint, target.thisT.position);

                    //if target is out of range already, set aggro status to false
                    if (targetDist > aggroRange * 2)
                    {
                        guardTriggered = false;
                        //if(anchorToPoint) GenerateNewAnchor();
                    }
                }
                else
                {
                    //if(anchorToPoint) MoveToPoint(currentAnchor, 0.5f);

                    //if target is close enough to aggor the unit, set guardTriggered to true so the target can be engaged in next frame
                    if (targetDist <= aggroRange)
                    {
                        guardTriggered = true;
                    }
                }
            }
        }