public void AttackTarget(Transform target) { IHaveStrength _myStats = GetComponent <IHaveStrength>(); if (_myStats != null) { if (!isAttacking) { isAttacking = true; StartCoroutine(AttackCooldown()); IHaveHealth _stats = target.GetComponent <IHaveHealth>(); if (_stats != null) { if (_stats.Health > 0) { //Do damage IDamagable _takeDamage = target.GetComponent <IDamagable>(); if (_takeDamage != null) { _takeDamage.ITakeDamage(_myStats.Strength, _stats); } } } } } }
private void Awake() { this.gameObject.SetActive(true); boxCollider2D.isTrigger = true; parent = GetComponentInParent <Actor>(); Debug.Log("The parent is: " + parent.name); //reference to the current health of the parent object's IHaveHealth Health property healthAmount = GetComponentInParent <IHaveHealth>(); }
public void SendDamageMessage(GameObject obj, int shooterID) { int id = _players.IndexOf(obj); IHaveHealth health = _players[id].GetComponent(typeof(IHaveHealth)) as IHaveHealth; float currentHealth = health.GetHealth(); string s = SerializationScript.SerializePlayerHealth(id, currentHealth, shooterID); SendData(s, 1, true); }
public void SetUp(HeadPlacement h, Transform p, IHaveHealth ph) { transform.position = p.transform.position + h.Offset; transform.localScale = h.ScaleValues; transform.SetParent(p); gameObject.AddComponent <SphereCollider>(); parent = p; parentHealth = ph; }
protected override void Deactivate() { Collider[] colliders = Physics.OverlapSphere(transform.position, _radius); foreach (Collider item in colliders) { IHaveHealth temp = item.GetComponent <IHaveHealth>(); if (temp != null) { temp.GetDamage(_damage); } } base.Deactivate(); }
/// <summary> /// Update a players health based on a health pack (host) /// </summary> /// <param name="splitCode">The message data from the packets</param> internal void HealthPlayer(string[] splitCode) { int id = int.Parse(splitCode[1]); float health = float.Parse(splitCode[2]); IHaveHealth target = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth; target.GainHealth(health); if (splitCode.Length >= 4) { int boxID = int.Parse(splitCode[3]); EventHealthPickUp(boxID); } }
internal void UpdateHealth(string[] splitCode) { int id = int.Parse(splitCode[1]); int shooterID = int.Parse(splitCode[3]); float currentHealth = float.Parse(splitCode[2]); IHaveHealth target = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth; float damage = target.GetHealth() - currentHealth; target?.TakeDamage(damage, shooterID); if (shooterID * -1 == _myID) { target?.SimulateDamage(network.GetPlayerOfID(id).transform.position + Vector3.up, damage); } }
// Start is called before the first frame update void Start() { if (haveHealth == null) { haveHealth = GetComponentInParent <IHaveHealth>(); } //Looks for an event of OnHealthChanged in the IHaveHealth variable haveHealth.OnHealthChanged += HaveHealth_OnHealthChanged; if (image == null) { image = GetComponent <Image>(); } //Changes the value of the slider to the value of the IHaveHealth variable image.fillAmount = haveHealth.Health / 100; }
void Hunt() { if (_reach != null) { if (_nav.agent.remainingDistance <= _reach.Reach) { if (curTarget != null) { IHaveHealth _health = curTarget.GetComponent <IHaveHealth>(); if (_health != null) { if (_health.Health > 0) { if (_attack != null) { _attack.AttackTarget(curTarget); } } else { if (_harvest != null) { _harvest.HarvestTarget(curTarget); } } } else if (curTarget.GetComponent <IAmPlant>() != null) { //Harvest if (_harvest != null) { _harvest.HarvestTarget(curTarget); } } } else { isHunting = false; } } } }
void UseAid(IHaveHealth health) { _healSystem.Heal(health, _value); SetEnable(false); }
public void Heal(IHaveHealth health, int value) { health.Health.Value = Mathf.Clamp(health.Health.Value + value, 0, health.MaxHealth.Value); }
/// <summary> /// Update the health of a player based on a health pack (client) /// </summary> /// <param name="id"> ID of the player to heal </param> /// <param name="health"> The amount to heal the player. </param> internal void HealthPlayer(int id, float health) { IHaveHealth target = network.GetPlayerOfID(id).GetComponent(typeof(IHaveHealth)) as IHaveHealth; target.GainHealth(health); }