void OnCollisionEnter(Collision col) { GetComponent <Rigidbody>().velocity = Vector3.zero; if (GetComponentInChildren <MeshRenderer>() != null) { GetComponentInChildren <MeshRenderer>().enabled = false; } else { Destroy(GetComponent <ParticleSystem>()); } gameObject.transform.GetChild(1).transform.gameObject.SetActive(true); float time = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().time; _duration = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().main.duration; _initDuration = gameObject.transform.GetChild(1).transform.gameObject.GetComponent <ParticleSystem>().main.duration; if (col.gameObject.tag == "Player" && !_didHit) { _didHit = true; DamageableEntity de = col.gameObject.GetComponent <DamageableEntity>(); Debug.Log("TravellingSpell::playerWhoSpawnedUs: " + playerWhoSpawnedUs); de.TakeDamage(playerWhoSpawnedUs, _damageAmount); GetComponent <Collider>().enabled = false; } _didHit = true; }
public void OnTriggerEnter2D(Collider2D collision) { // Is it damageable? DamageableEntity damageable = collision.gameObject.GetComponent <DamageableEntity>(); if (damageable) { if (onHit != null) { onHit.Invoke(collision.gameObject); } // Deal your damage // Possibility of a persistent projectile / hit-point system? if (OnAttackHit != null) { OnAttackHit.Invoke(); } damageable.TakeDamage(Damage); } // Is it a ghost? Transform parent = collision.gameObject.transform.parent; if (parent != null) { GhostMovement ghost = parent.GetComponentInChildren <GhostMovement>(); if (ghost != null) { ghost.Knockback(transform.up * knockbackForce); } } }
void OnParticleCollision(GameObject other) { if (other.tag == "Player") { DamageableEntity de = other.GetComponent <DamageableEntity>(); de.TakeDamage(SteamClient.Name, _damage); } }
protected virtual void OnCollisionEnter(Collision collisionInfo) { KillThisObject(); DamageableEntity d = collisionInfo.collider.GetComponent <DamageableEntity>(); if (d != null) { d.TakeDamage(damage); } }
public void OnTriggerEnter2D(Collider2D collision) { // Is it damageable? DamageableEntity damageable = collision.gameObject.GetComponent <DamageableEntity>(); if (damageable) { if (onHit != null) { onHit.Invoke(collision.gameObject); } // Deal your damage // Possibility of a persistent projectile / hit-point system? Debug.Log("Hit!" + collision.name); damageable.TakeDamage(Damage); } }
private void OnCollisionEnter2D(Collision2D other) { GameObject hitObject = other.gameObject; if (OnImpact != null) { OnImpact(); } DamageableEntity hitEntity = hitObject.GetComponent <DamageableEntity>(); if (hitEntity != null) { hitEntity.TakeDamage(damage); } Remove(); }
public void OnTriggerEnter2D(Collider2D collision) { // Is it damageable? DamageableEntity damageable = collision.gameObject.GetComponentInChildren <DamageableEntity>(); if (damageable) { if (onHit != null) { onHit.Invoke(collision.gameObject); } // Deal your damage damageable.TakeDamage(Damage); // Have a refresh system so you can take damage many times if he's over you all the time StartCoroutine(RefreshHitbox()); } }
// We collided with something! private void OnTriggerEnter2D(Collider2D collision) { DamageableEntity damageable = null; // Is it damageable? damageable = collision.GetComponent <DamageableEntity>(); if (damageable) { if (onHit != null) { onHit.Invoke(collision.gameObject); } // Deal your damage // Possibility of a persistent projectile / hit-point system? damageable.TakeDamage(Damage); // Destroy itself Destroy(gameObject); } }