public override bool CheckCondition() { Targetter targetter = null; List <Targetable> targets = new List <Targetable>(); Tower tower = activeUnit as Tower; foreach (Affector affector in tower.currentTowerLevel.Affectors) { var attack = affector as AttackAffector; if (attack != null && attack.damagerProjectile != null) { targets = attack.targetter.GetAllTargets(); targetter = attack.targetter; } } if (targetter) { targetter.targetEntersRange += Targetter_targetEntersRange; targetter.targetExitsRange += Targetter_targetExitsRange; } for (int i = 0; i < targets.Count; i++) { targets[i].died += TowerCloseDeathCondition_died; } return(false); }
protected virtual void Start() { center = transform.parent; alignment = transform.parent.parent.GetComponent <Tower>().configuration.alignmentProvider; targetter = transform.parent.GetComponentInChildren <Targetter>(); targetter.acquireTargetable += OnAcquiredTarget; targetter.loseTargetable += OnLostTarget; }
protected virtual void Start() { playerTag = GetComponent <PlayerTag> (); movementScript = GetComponent <Base_Movement> (); healthScript = GetComponent <Base_Health> (); body = GetComponent <Rigidbody2D> (); targetter = GetComponentInChildren <Targetter> (); }
public void Execute(GameObject _actor) { var target = Targetter.GetClosest(_actor.transform.position, GetTargets(_actor)); if (target != null) { target.GetComponent <Interactable>().Interact(); } }
protected virtual void Start() { line = this.gameObject.AddComponent <LineRenderer>(); line.material = mat; line.startWidth = line.endWidth = 2f; // Set the number of vertex fo the Line Renderer line.positionCount = 2; alignment = transform.parent.parent.GetComponent <Tower>().configuration.alignmentProvider; targetter = transform.parent.GetComponentInChildren <Targetter>(); damager = GetComponent <Damager>(); if (zone != null) { float rad = targetter.effectRadius * 2; zone.localScale = new Vector3(rad, rad, rad); } }
public void Execute(GameObject _actor) { var target = Targetter.GetClosest(_actor.transform.position, GetTargets(_actor)); if (target != null) { //AudioSource.PlayClipAtPoint(chopAudio.clip, _actor.transform.position); chopAudio.Play(); var resourceAmount = target.GetComponent <Choppable>().GetChopped(_power); if (resourceAmount > 0) { Debug.Log("Collected " + resourceAmount + "inches of wood."); } } }
/// <summary> /// Caches the collider and hides it /// and configures all the necessary information from it /// </summary> void OnEnable() { m_Targetter = (Targetter)target; m_SerializedAttachedCollider = serializedObject.FindProperty("attachedCollider"); m_AttachedCollider = (Collider)m_SerializedAttachedCollider.objectReferenceValue; if (m_AttachedCollider == null) { m_AttachedCollider = m_Targetter.GetComponent <Collider>(); if (m_AttachedCollider == null) { switch (m_ColliderConfiguration) { case TargetterCollider.Sphere: m_AttachedCollider = m_Targetter.gameObject.AddComponent <SphereCollider>(); break; case TargetterCollider.Capsule: m_AttachedCollider = m_Targetter.gameObject.AddComponent <CapsuleCollider>(); break; } m_SerializedAttachedCollider.objectReferenceValue = m_AttachedCollider; } } if (m_AttachedCollider is SphereCollider) { m_ColliderConfiguration = TargetterCollider.Sphere; } else if (m_AttachedCollider is CapsuleCollider) { m_ColliderConfiguration = TargetterCollider.Capsule; } // to ensure the collider is referenced by the serialized object if (m_SerializedAttachedCollider.objectReferenceValue == null) { m_SerializedAttachedCollider.objectReferenceValue = m_AttachedCollider; } GetValues(); m_AttachedCollider.isTrigger = true; m_AttachedCollider.hideFlags = HideFlags.HideInInspector; }
public virtual void Ini(GameObject parent, int id, int team, bool _released) { playerTag = GetComponent <PlayerTag> (); movementScript = GetComponent <Base_Movement> (); healthScript = GetComponent <Base_Health> (); targetter = GetComponentInChildren <Targetter> (); if (playerTag == null) { playerTag = GetComponent <PlayerTag> (); } playerTag.SetId(id); playerTag.SetTeam(team); if (_released) { Release(); } else { parentObject = parent; } }
// Start is called before the first frame update void Start() { lightTarget = GetComponent <Targetter>(); }
private void Awake() { targetter = GetComponentInChildren <Targetter>(); targetter.setRange(levelData.range); }
void FixedUpdate() { // The towers will be updating their positions and scale in their own update functions. // The following section of code will let's the metadata system know that this // is the particular metadata we want to send down to the clients. //dyanmically get the towers that exist. Update the tower array GameObject[] towersObj = GameObject.FindGameObjectsWithTag("Tower"); towers = new Tower[towersObj.Length]; // The towers will be updating their positions and scale in their own update functions. // The following section of code will let's the metadata system know that this // is the particular metadata we want to send down to the clients. metadataUpdateParms.items = new ServerTowerInformation[towers.Length]; for (var i = 0; i < towersObj.Length; i++) { towers[i] = towersObj[i].GetComponent <Tower>(); } for (var k = 0; k < towersObj.Length; k++) { //var screenPos = APG.Helper.ScreenPosition(mainCamera, towers[k]); /* use the getcollider function and then get the 8 coords to enter into the * worldtoscreenfunc and then get the top left (max x and min y) * Also get the bottom right corner and pass into the for loop in line 85. * Scale is abs(bottomright-topleft) */ Collider col = towers[k].getCollider(); Vector2 wFrontTopLeft = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.min.x, col.bounds.max.y, col.bounds.min.z)); Vector2 wFrontTopRight = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.max.x, col.bounds.max.y, col.bounds.min.z)); Vector2 wFrontBottomRight = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.max.x, col.bounds.min.y, col.bounds.min.z)); Vector2 wFrontBottomLeft = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.min.x, col.bounds.min.y, col.bounds.min.z)); Vector2 wBackTopLeft = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.min.x, col.bounds.max.y, col.bounds.max.z)); Vector2 wBackTopRight = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.max.x, col.bounds.max.y, col.bounds.max.z)); Vector2 wBackBottomRight = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.max.x, col.bounds.min.y, col.bounds.max.z)); Vector2 wBackBottomLeft = APG.Helper.ScreenPosition(mainCamera, new Vector3(col.bounds.min.x, col.bounds.min.y, col.bounds.max.z)); /* Get Max and Min bounding box positions */ var topLeftX = Mathf.Min(wFrontTopLeft.x, wFrontTopRight.x, wFrontBottomRight.x , wFrontBottomLeft.x, wBackTopLeft.x, wBackTopRight.x , wBackBottomRight.x, wBackBottomLeft.x); var topLeftY = Mathf.Max(wFrontTopLeft.y, wFrontTopRight.y, wFrontBottomRight.y , wFrontBottomLeft.y, wBackTopLeft.y, wBackTopRight.y , wBackBottomRight.y, wBackBottomLeft.y); var bottomRightX = Mathf.Max(wFrontTopLeft.x, wFrontTopRight.x, wFrontBottomRight.x , wFrontBottomLeft.x, wBackTopLeft.x, wBackTopRight.x , wBackBottomRight.x, wBackBottomLeft.x); var bottomRightY = Mathf.Min(wFrontTopLeft.y, wFrontTopRight.y, wFrontBottomRight.y , wFrontBottomLeft.y, wBackTopLeft.y, wBackTopRight.y , wBackBottomRight.y, wBackBottomLeft.y); metadataUpdateParms.items[k].x = (int)topLeftX; metadataUpdateParms.items[k].y = (int)topLeftY; metadataUpdateParms.items[k].scaleX = (int)Mathf.Abs(bottomRightX - topLeftX); metadataUpdateParms.items[k].scaleY = (int)Mathf.Abs(bottomRightY - topLeftY); /* Get Tower Information */ TowerLevelData data = towers[k].GetComponentInChildren <TowerLevel>().levelData; AttackAffector attack = towers[k].GetComponentInChildren <AttackAffector>(); metadataUpdateParms.items[k].attack = attack.projectile.GetComponent <Damager>().damage; metadataUpdateParms.items[k].fireRate = attack.fireRate; Targetter target = towers[k].GetComponentInChildren <Targetter>(); metadataUpdateParms.items[k].radius = target.effectRadius; metadataUpdateParms.items[k].name = towers[k].towerName; } }