// If collider is attached to player or minion or just about anything // with a HealthBehavior script then heal it. // We just don't want this building healing other buildings. //private void OnTriggerStay(Collider other) //{ // HealthBehavior hb = other.gameObject.GetComponent<HealthBehavior>(); // if (hb == null) return; //} /// <summary> /// Adds a reference to other's GameObject /// if it is eligible for healing. /// GameObjects eligible are any objects which have HealthBehaviors, /// but are not buildings. /// </summary> /// <param name="other"></param> //protected override void OnTriggerEnter(Collider other) { // GameObject go = other.gameObject; // if ( ( taggyBoi.isP1Tag(this.tag) && taggyBoi.isP1Tag(go.tag)) // || ( taggyBoi.isP2Tag(this.tag) && taggyBoi.isP2Tag(go.tag))) { // // TODO: exclude buildings // healables.Add(go); // } //} /// <summary> /// Since other's GameObject is exiting the healing zone, /// it is no longer eligible for healing. /// If it was previously eligible, /// it will be removed /// </summary> /// <param name="other"></param> //private void OnTriggerExit(Collider other) { // GameObject go = other.gameObject; // if (healables.Contains(go)) { // healables.Remove(go); // } //} /// <summary> /// Populates this script's internal healables collection. /// Checks colliders in a radius around this object. /// If they are eligible to be healed, /// adds their GameObject to the healables collection. /// Note that this healables collection should be flushed at the end of every frame, /// because this function will be called next frame. /// </summary> private void populateHealables() { Collider[] overlaps = Physics.OverlapSphere(gameObject.transform.position, healRadius); foreach (Collider c in overlaps) { GameObject go = NPCShootController.FindParentObject(c.gameObject.transform); HealthBehavior hb = (go == null ? null : go.GetComponent <HealthBehavior>()); // Exclude things which don't have HealthBehaviors if (hb == null) { continue; } // Exclude buildings (else, healing buildings would be pretty broken) if (taggyBoi.isStructure(go.tag)) { continue; } // Don't heal if they're dead if (!hb.isNotDead()) { continue; } // Only heal if us and go are of the same team if ((taggyBoi.isP1Tag(this.gameObject.tag) && taggyBoi.isP1Tag(go.tag)) || (taggyBoi.isP2Tag(this.gameObject.tag) && taggyBoi.isP2Tag(go.tag))) { healables.Add(go); } } }
public void ManualAbilityCancel() { if (abilityActive && !isCoolingDown) { switch (abilityType) { case AbilityType.defend: { abilityActive = false; HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.EnableBlockDamage(false); player.AbilityInUse(false); player.SetMyAnimator("EndDefense"); EnableAbilityLabels(); } break; case AbilityType.stun: { abilityActive = false; EnableAbilityLabels(); } break; case AbilityType.dodge: { } break; } } }
/// <summary> /// Detects the targets in range. That is, gets all GameObjects with the /// specified layer in range. This method guarantees that no duplicate /// GameObjects will be returned. /// </summary> /// <returns>A List of GameObjects representing the targets in range.</returns> public List <GameObject> DetectTargets() { // Make room for new targets targets.Clear(); //Debug.Log(name + ": clearing targets"); // Get all of the colliders in range Collider[] colliders = Physics.OverlapSphere(transform.position, range, targetLayerMask); //Debug.Log(name + ": Found " + colliders.Length + " colliders"); // Add the GameObjects of the colliders to the targets list foreach (Collider c in colliders) { GameObject target = FindParentObject(c.transform); Assert.IsTrue(target != null, "target " + target.name + " is null"); Assert.IsTrue(targets != null, "targets is null"); HealthBehavior hb = target.GetComponent <HealthBehavior>(); Assert.IsTrue(hb != null, "Health behavior of target " + target.name + " is null,\n" + "i.e. " + target.name + " does not have a HealthBehavior"); //Debug.Log(name + ": Target found: " + target); // Make sure we don't add duplicate references to the same GameObject // Make sure we don't add dead GameObjects to the targets. if (!targets.Contains(target) && hb.isNotDead()) { //Debug.Log(name + ": Target added: " + target); targets.Add(target); } } //Debug.Log(name + ": Total targets: " + targets.Count); return(targets); }
/// <summary> /// Determines the closest target from the <see cref="targets"/> /// list of GameObjects. Priority is determined by the implementing class. /// This method assumes a full list of targets (filled by DetectTargets). /// </summary> /// <returns>The GameObject of the closest target, or <c>null</c> if there /// are no targets in the list.</returns> public GameObject DetermineClosestTarget() { GameObject closest = null; float minDist = float.MaxValue; float tempDist; //Debug.Log(name + ": DetermineClosestTarget count: " + targets.Count); foreach (GameObject g in targets) { tempDist = (g.transform.position - transform.position).magnitude; if (tempDist < minDist) { minDist = tempDist; closest = g; } } if (closest) { //Debug.Log(name + ": Closest Target: " + closest.name); } if (closest != null) { targetHealth = closest.GetComponent <HealthBehavior>(); } return(closest); }
public void ResetEnemy() { myHealth = GetComponent <HealthBehavior>(); myOffense = GetComponent <OffenseBehavior>(); myHealth.ResetHealth(); myHealth.UpdateHealthBar(); Invoke("AttackCyclePrimer", attackRateInSeconds); }
void SetUpPlayerStats() { HealthBehavior playerHealth = GameObject.FindObjectOfType <PlayerBehaviour>().GetComponent <HealthBehavior>(); playerHealth.SetMaxHealth(10); playerHealth.SetDefenseValue(0); playerHealth.GetComponent <OffenseBehavior>().SetAttackPower(1); }
// Update is called once per frame void OnTriggerEnter(Collider other) { HealthBehavior health = other.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(Damage); } }
public void StunThisOffense(float stunTime) { HealthBehavior myHealth = GetComponent <HealthBehavior>(); if (!myHealth.GetInvulnerabilityStatus()) { StartCoroutine(IAmStunned(stunTime)); } }
protected virtual void Awake() { bulletPool = new QueueObjectPooler <RecyclableBullet>(bullet, bulletFondler, maxBullets); health = GetComponent <HealthBehavior>(); targets = new List <GameObject>(); tempTargets = new List <GameObject>(); priorities = new Dictionary <string, int>(); DefinePriorities(); targetLayerMask = DetermineTargetLayer(); }
public void UseAbility() { if (!abilityActive && GameObject.FindObjectOfType <ProgressTracker>().GameStillInSession() && !player.GetAbilityUseStatus()) { switch (abilityType) { case AbilityType.defense: { abilityActive = true; HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.SetDividerValue(potency + 1); playerHealth.EnableBlockDamage(true); player.AbilityInUse(true); player.SetMyAnimator("StartDefense"); if (abilityEffectPrefab) { activeAbilityEffect = Instantiate(abilityEffectPrefab, player.transform.position, Quaternion.identity); activeAbilityEffect.transform.parent = player.transform; activeAbilityEffect.transform.position = player.transform.position; } DisableAbilityLabels(); } break; case AbilityType.dodge: { abilityActive = true; HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.SetAbsorbAttack(true, potency); player.AbilityInUse(true); player.SetMyAnimator("Dodge"); DisableAbilityLabels(); } break; case AbilityType.stun: { abilityActive = true; OffenseBehavior playerOffense = player.GetComponent <OffenseBehavior>(); playerOffense.AbilityAttack(abilityType, potency); player.SetMyAnimator("stunAttack"); DisableAbilityLabels(); coolDownTime = Mathf.Clamp(coolDownTime + 1f, 1f, 10f); } break; default: { Debug.Log("Ability was not specified. cannot be used."); } break; } if (coolDownTime > 0) { StartCoroutine(CoolDownAbility(coolDownTime)); } } }
public void UseItem() { if (currentReserve > 0 && !effectActive && GameObject.FindObjectOfType <ProgressTracker>().GameStillInSession()) { player = GameObject.FindObjectOfType <PlayerBehaviour>(); HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); switch (itemType) { case ItemType.healing: { if (player && playerHealth.GetCurrentHealth() > 0) { playerHealth.IncreaseHealth(potency); DecreaseCurrentReserveBy(1); DisplayEffect(player.transform); } } break; case ItemType.buff: { if (player && playerHealth.GetCurrentHealth() > 0) { /*int isDeadHash = Animator.StringToHash("Dead"); * AnimatorStateInfo info = player.GetPlayerAnimator().GetCurrentAnimatorStateInfo(0); * Debug.Log("Player's current int state is: " + info.fullPathHash); * Debug.Log("Player's dead animation state is: " + isDeadHash);*/ OffenseBehavior playerAtk = player.GetComponent <OffenseBehavior>(); playerAtk.BuffAttackPowerBy(potency, timeLengthOfEffect); effectActive = true; Invoke("EndOfEffect", timeLengthOfEffect + 0.5f); DecreaseCurrentReserveBy(1); } } break; case ItemType.damage: { enemy = GameObject.FindObjectOfType <EnemyBehaviour>(); HealthBehavior enemyHealth = enemy.GetComponent <HealthBehavior>(); if (enemy && playerHealth.GetCurrentHealth() > 0 && enemyHealth.GetCurrentHealth() > 0) { enemyHealth.ReduceHealth(potency); StartCoroutine(DisplayAndTrackEffect(enemy.transform)); DecreaseCurrentReserveBy(1); } } break; default: { Debug.Log("Item Type for this item was not specified."); } break; } } else { Debug.Log("Cannot use this Item anymore"); } }
private void OnTriggerEnter(Collider other) { Destroy(other.gameObject); HealthBehavior health = _player.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(1); } }
private void OnTriggerEnter(Collider enemy) { //Get the health behavior attached to the object HealthBehavior health = enemy.GetComponent <HealthBehavior>(); //If the health value is not null, deal damage if (health) { health.TakeDamage(Damage); } }
private void Start() { myHealth = GetComponent <HealthBehavior>(); myOffense = GetComponent <OffenseBehavior>(); gameState = GameObject.FindObjectOfType <ProgressTracker>(); myHealth.ResetHealth(); myHealth.UpdateHealthBar(); if (items[0]) { SetItemUsesToMax(); } }
private void PrimeNewEnemy() { enemyOffenseStats = enemy.GetComponent <OffenseBehavior>(); enemyOffenseStats.SetAttackPower(enemyOffenseStats.GetAttackPower()); enemyHealthStats = enemy.GetComponent <HealthBehavior>(); enemyHealthStats.SetMaxHealth(enemyHealthStats.maxHealth); enemyAi = enemy.GetComponent <EnemyBehaviour>(); enemyAi.SetAttackRate(enemyAi.attackRateInSeconds); enemyAi.ResetEnemy(); }
private void OnTriggerEnter(Collider other) { HealthBehavior otherHealth = other.GetComponent <HealthBehavior>(); if (otherHealth == null) { Destroy(gameObject); } else { otherHealth.TakeDamage(_damage); } }
// Start is called before the first frame update void Start() { GameObject playerBase; if(isP1){ playerBase = GameObject.FindWithTag("P1_Base"); } else{ playerBase = GameObject.FindWithTag("P2_Base"); } hb = playerBase.GetComponent<HealthBehavior>(); star = GetComponent<Image>(); denominator = (float) hb.maxHealth; }
//To be used later maybe when we need to declare other global variables // that don't belong in above categories #endregion // Start is called before the first frame update void Start() { // Determine which OS the game is being run on, and set controller // mappings accordingly. switch (Application.platform) { case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: forwardDrive = (tag == "Player1_obj" ? "forward-drive-1-mac" : "forward-drive-2-mac"); backwardDrive = (tag == "Player1_obj" ? "backward-drive-1-mac" : "backward-drive-2-mac"); reverse = (tag == "Player1_obj" ? "reverse-1-mac" : "reverse-2-mac"); buildButton = (tag == "Player1_obj" ? "build-1-mac" : "build-2-mac"); selectBuildButton = (tag == "Player1_obj" ? "select-1-mac" : "select-2-mac"); submitButton = (tag == "Player1_obj" ? "submit-1-mac" : "submit-2-mac"); break; case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: forwardDrive = (tag == "Player1_obj" ? "forward-drive-1-win" : "forward-drive-2-win"); backwardDrive = (tag == "Player1_obj" ? "backward-drive-1-win" : "backward-drive-2-win"); reverse = (tag == "Player1_obj" ? "reverse-1-win" : "reverse-2-win"); buildButton = (tag == "Player1_obj" ? "build-1-win" : "build-2-win"); selectBuildButton = (tag == "Player1_obj" ? "select-1-win" : "select-2-win"); submitButton = (tag == "Player1_obj" ? "submit-1-win" : "submit-2-win"); break; default: Debug.LogError("Mappings not setup for operating systems other than Windows or Mac OS"); break; } // Left analog stick is the same mapping on Mac OS and Windows xDrive = (tag == "Player1_obj" ? "x-drive-1" : "x-drive-2"); zDrive = (tag == "Player1_obj" ? "z-drive-1" : "z-drive-2"); // Define movement starting values stickInput = new Vector3(); rb = transform.GetComponent <Rigidbody>(); dir = 1; // Define resource starting values Fluff = 0; Plastic = 0; // Get the reference to the HealthBehavior script hb = GetComponent <HealthBehavior>(); state = TankStates.Alive; wasNotDead = hb.isNotDead(); GetComponent <Rigidbody>().maxAngularVelocity = turnSpeed; }
///<summary> /// Places the correct images and text into the fields of HealthBehavior /// for the player. ///</summary> void InitializeHealthBehavior(GameObject player, GameObject cav) { HealthBehavior hb = player.GetComponent <HealthBehavior>(); hb.health_icon = cav.transform.Find("Heart_back/Heart_health").gameObject.GetComponent <Image>(); hb.respawn_background = cav.transform.Find("Respawn_back").gameObject.GetComponent <Image>(); hb.health_val = cav.transform.Find("Heart_back/Health_Text").gameObject.GetComponent <Text>(); hb.respawnText = cav.transform.Find("Respawn_back/Respawn_Text").gameObject.GetComponent <Text>(); hb.health_icon.fillAmount = 1.0f; hb.health_val.text = hb.maxHealth.ToString(); hb.respawnText.gameObject.SetActive(false); hb.respawn_background.gameObject.SetActive(false); }
//What happens when the object touches the player private void OnCollisionEnter(Collision other) { if (!other.gameObject != _movement.gameObject) { return; } HealthBehavior health = other.gameObject.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(_damage); } }
//COMPLETE WHEN HEALTHBEHAVIOUR IS DONE private void OnTriggerEnter(Collider other) { //Create a HealthBehaviour variable and set it equal to the health of what the bullet collides with HealthBehavior health = other.GetComponent <HealthBehavior>(); //check owner on collision before dealing damage if (other.gameObject != Owner) { //If the bullet collides with something that has health, call TakeDamage if (health) { health.TakeDamage(Damage); } } }
private void OnCollisionEnter(Collision collision) { //If the collided object isn't the target, return if (collision.gameObject != _movement.target) { return; } HealthBehavior health = collision.gameObject.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(_damage); } }
public void AbilityAttack(AbilityType abilityMove, int dmgStrength) { switch (abilityMove) { case AbilityType.stun: { HealthBehavior theirHealth = target.GetComponent <HealthBehavior>(); if (theirHealth) { target.GetComponent <OffenseBehavior>().StunThisOffense(target.GetComponent <EnemyBehaviour>().attackRateInSeconds * 1.1f); } int multiplier = (int)Mathf.Clamp(dmgStrength / 3, 0, 1); AttackTarget(attackPower * multiplier); } break; } }
private void PrimeNewEnemy() { enemyOffenseStats = enemy.GetComponent <OffenseBehavior>(); enemyOffenseStats.SetAttackPower(enemyOffenseStats.GetAttackPower() + multiplier); enemyHealthStats = enemy.GetComponent <HealthBehavior>(); enemyHealthStats.SetMaxHealth(enemyHealthStats.maxHealth * multiplier); enemyHealthStats.SetDefenseValue(enemyHealthStats.GetDefenseValue() + multiplier); enemyAi = enemy.GetComponent <EnemyBehaviour>(); //enemyAi.SetAttackRate(enemyAi.attackRateInSeconds); enemyAi.winningsValue *= multiplier; pendingWinnings = enemy.GetComponent <EnemyBehaviour>().winningsValue; multiplier = (enemyPool.enemyIndex + 1) * difficultyScale; }
// Start is called before the first frame update protected virtual void Start() { health = GetComponent <HealthBehavior>(); health.setHealth(maxHealth); shooter = GetComponent <MinionShootController>(); anim = GetComponent <Animator>(); leftRight = getAxisString(true); upDown = getAxisString(false); altHalt = getAltHalt(); // Set base information if (P1_Base == null) { P1_Base = GameObject.FindWithTag("P1_Base"); } if (P2_Base == null) { P2_Base = GameObject.FindWithTag("P2_Base"); } Assert.IsTrue(taggyboi.isMinion(tag), "Minion tag " + tag + " improperly set"); homeBase = (taggyboi.isP1Tag(tag) ? P1_Base.transform : P2_Base.transform); enemyBase = (taggyboi.isP1Tag(tag) ? P2_Base.transform : P1_Base.transform); // Start them off by standing still until they get an order. moveType = lastType = MinionMoveTypes.Halt; // Both Soldiers and Teddies are allowed to start moving immediately State = MinionStates.Move; StartCoroutine(TargetSearch()); if (debugOnce) { //StartCoroutine(PrintStates()); //StartCoroutine(PrintDpad()); debugOnce = false; } }
/// <summary> /// Iterates through healables and heals them all based on healRate, /// only when t > 1.0f. /// If t is less than 1.0f, /// this function has no effect. /// </summary> private void healHealables() { if (t < 1.0f) { return; } foreach (GameObject g in healables) { HealthBehavior hb = g.GetComponent <HealthBehavior>(); // hb better be valid before we heal it! Assert.IsTrue(hb != null, g.name + " does not have a HealthBehavior script attached"); Assert.IsTrue(hb.isActiveAndEnabled, g.name + "'s HealthBehavior either is inactive or disabled"); hb.adjustHealth(healRate); } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.name.Contains("SquareTarget")) { ScoreBehavior.UpdateScore(1); } else if (collision.gameObject.name == "right") { UISelection.OnRightSelected(); } else if (collision.gameObject.name == "left") { UISelection.OnLeftSelected(); } else { HealthBehavior.UpdateHealth(); } }
private void DealDamage() { // Deal damage to all objects that sc touches Collider[] colliders = Physics.OverlapSphere(bullet.transform.position, radius); foreach (Collider c in colliders) { GameObject go = c.gameObject; if (tagManager.isShootable(go.tag)) { HealthBehavior hb = go.GetComponent <HealthBehavior>(); Assert.IsTrue(hb != null, go.name + " does not have a HealthBehavior attached,\n" + "and " + bullet.name + " just tried to deal damage to it"); hb.adjustHealth(-damage); } } }
public void CancelAbility(string cancelType) { if (abilityActive && !isCoolingDown) { switch (abilityType) { case AbilityType.defense: { abilityActive = false; HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.EnableBlockDamage(false); player.AbilityInUse(false); player.SetMyAnimator("EndDefense"); EnableAbilityLabels(); } break; case AbilityType.dodge: { if (cancelType.Equals("dodge")) { abilityActive = false; HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.SetAbsorbAttack(false, 0); player.AbilityInUse(false); EnableAbilityLabels(); } } break; case AbilityType.stun: { abilityActive = false; OffenseBehavior playerOffense = player.GetComponent <OffenseBehavior>(); EnableAbilityLabels(); } break; } if (activeAbilityEffect) { Destroy(activeAbilityEffect); } } }
public void SpecialAbilityCancel() { if (abilityActive) { switch (abilityType) { case AbilityType.dodge: { if (!isCoolingDown) { abilityActive = false; EnableAbilityLabels(); } HealthBehavior playerHealth = player.GetComponent <HealthBehavior>(); playerHealth.SetAbsorbAttack(false, 0); player.AbilityInUse(false); } break; } } }