public override void OnTargetLock(RTSGameObject rtsGameObject) { if (isPursuing) { StopMoving(); } }
//------------------------------ Attacking ------------------------------ #region Attacking public override void Attack(RTSGameObject rtsGameObject) { if (targetToPursue != rtsGameObject) //If we are not aleready pursuing this RTS target { targetToPursue = HoverManager.main.currentHoverRTSObject; if (isTargetLock) //We are already targeting someone { targetLock = targetToPursue; if (coroutineAttack != null) { StopCoroutine(coroutineAttack); } coroutineAttack = StartCoroutine(Attack(turret, targetLock.gameObject)); } else //If we do not yet have a targetLock { } TravelToPath(targetToPursue.transform.position); } else { //Debug.Log("Already pusuing this target."); } }
//------------------------------ OnTargetLock ------------------------------ #region OnTargetLock public override void OnTargetLockEnter(RTSGameObject rtsGameObject) { if (coroutineAttack != null) { StopCoroutine(coroutineAttack); } coroutineAttack = StartCoroutine(Attack(turret, targetLock.gameObject)); }
public void StopAttacking() { isAttacking = false; targetToPursue = null; targetLock = null; if (coroutineAttack != null) { StopCoroutine(coroutineAttack); } OnAttackingEnd(); //Method message }
public override void OnAttacking(RTSGameObject rtsGameObject) { //Debug.Log("OnAttacking"); }
public override void OnPursuing(RTSGameObject rtsGameObject) { //Debug.Log("OnPursuing"); }
public override void Attack(RTSGameObject rtsGameObject) { //Todo: }
} //Called while this object has found a target lock public virtual void OnTargetLockLeave(RTSGameObject rtsGameObject) { } //Called once when this object has lost it's target lock
} //Called once when this object has found a target lock public virtual void OnTargetLock(RTSGameObject rtsGameObject) { } //Called while this object has found a target lock
} //Called while object is searching for a target lock public virtual void OnTargetLockEnter(RTSGameObject rtsGameObject) { } //Called once when this object has found a target lock
public abstract void Attack(RTSGameObject rtsGameObject);
public virtual void Update() { if (teamController != null && canAttack) //If we have a teamController && If we can attack { if (!isTargetLock) //If we dont have a target lock { OnTargetLockSearch(); //Method message //Searching for targetLock using attack radius RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, attackRadius, Vector3.up); foreach (RaycastHit hit in hits) { GameObject hitGameObject = hit.collider.gameObject; if (hitGameObject != gameObject) //If the gameObject is not ourself { RTSGameObject hitRTSGameObject = hitGameObject.GetComponent <RTSGameObject>(); if (hitRTSGameObject != null) //If the object is a RTSGameObject //if(hitRTSGameObject.unitType == UnitType.UnitEnemy || hitRTSGameObject.unitType == UnitType.BuildingEnemy) { // FindTargetLock(hitGameObject); //} { if (teamController.IsRTSEnemy(hitRTSGameObject)) { FindTargetLock(hitGameObject); } if (teamController.team == Team.Red) { //Debug.Log("Attack: " + attackRadius); } } } } } //If we do have a target lock else { bool hasFoundTargetLock = false; //Check if the lock target still within range RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, attackRadius, Vector3.up); foreach (RaycastHit hit in hits) { GameObject hitGameObject = hit.collider.gameObject; if (hitGameObject.GetComponent <RTSGameObject>() == targetLock) //If we have found our target lock { hasFoundTargetLock = true; break; } } if (hasFoundTargetLock) //If the target lock is still within range //Debug.Log("Found target"); { OnTargetLock(targetLock); //Method message } else //If the target left { OnTargetLockLeave(targetLock); //Method message targetLock = null; } } } if (health <= 0) { Destroy(); } }
} //Called once when this object starts attacking another object. public virtual void OnAttacking(RTSGameObject rtsGameObject) { } //Called while this object is attacking another object.
} //Called once when this object has lost it's target lock public virtual void OnAttackingStart(RTSGameObject rtsGameObject) { } //Called once when this object starts attacking another object.
public override void OnTargetLockLeave(RTSGameObject rtsGameObject) { StopAttacking(); }
//Method Messages public virtual void OnPursuing(RTSGameObject rtsGameObject) { } //Called while this object is pursuing another object.