public void FixedUpdate() { if (isHitted) { return; } Vector3 finalPos = Transform.position + Transform.forward * speed * Time.fixedDeltaTime; if (Physics.Linecast(Transform.position, finalPos, out RaycastHit hit)) { isHitted = true; Transform.position = hit.point - Transform.forward * hitDelta; IDamageable damageable = hit.collider.GetComponent <IDamageable>(); if (damageable != null) { damageable.ApplyDamage(damage * damageMultiplyer, Transform.forward); } BulletHittedAction(); //Destroy(GameObject, selfDestroyTimeAfterHit); Invoke("Disable", selfDestroyTimeAfterHit); } else { Transform.position = finalPos; damageMultiplyer += damageChangeOverTime; } }
IEnumerator FireballEffect(float visualsTimer) { //Visuals or particleFX; List <Transform> enemyUnits = targetManager.FindAllTargetsWithinRadius(gameObject.transform, thisPlayer, attackRadius); foreach (Transform unit in enemyUnits) { IDamageable healthScript = unit.GetComponent <IDamageable>(); if (healthScript != null) { healthScript.ApplyDamage(attackPower); } } for (int i = 0; i <= 2; i++) //Spawns the minion in a row, each one unit to the right from the previous { Instantiate(barrelMinion, new Vector3(transform.position.x + i * 0.5f, transform.position.y - 1, transform.position.z), Quaternion.identity, gameObject.transform.parent.parent); } GameObject parent = transform.parent.gameObject; yield return(new WaitForSeconds(visualsTimer)); Destroy(parent); }
/// <summary> /// Checks for an IDamagable on the target GameObject, then attempts to call its ApplyDamage method. /// If an IDamagable isn't found, returns false. /// </summary> /// <param name="damageTarget"> The Target to look for an IDamagable on.</param> /// <param name="args"> Damage Event Arguments.</param> /// <returns></returns> public virtual bool TryDealDamage(GameObject damageTarget, Damage.DamageEventArgs args) { if (!CanDealDamage) { return(false); } if (args.DamageValue <= 0) { return(false); } IDamageable damageable = damageTarget.GetComponent <IDamageable>(); if (damageable != null) { if (this.faction == damageable.GetFaction() && !Damage.FriendlyFireEnabled) { return(false); } // By using a ref parameter, we can see the results of the damage delt after it has been changed by resistances and multipliers. damageable.ApplyDamage(this, ref args); if (args.DamageValue > 0) { OnDealDamage(damageable, args); return(true); } } // No IDamagable Found - Return false. return(false); }
void OnCollisionEnter(Collision other) { // Don't destroy other asteroids if (other.gameObject.GetComponent <Asteroid>() != null) { other.rigidbody.AddForce( rb.velocity, ForceMode.Impulse ); } else { IDamageable dmg = other.gameObject.GetComponent <IDamageable>(); if (dmg != null) { var otherBody = other.gameObject.GetComponent <Rigidbody>(); if (otherBody != null) { otherBody.AddForce( rb.velocity, ForceMode.Impulse ); } dmg.ApplyDamage(this.gameObject, other.collider, this.damage); } } }
private void FixedUpdate() { if (isHitted) { collParticle.Play(); return; } var finalPos = transform.position + transform.forward * speed * Time.fixedDeltaTime; RaycastHit hit; if (Physics.Linecast(transform.position, finalPos, out hit, layerMask)) { isHitted = true; transform.position = hit.point; IDamageable box = hit.collider.GetComponent <IDamageable>(); if (box != null) { box.ApplyDamage(damage, transform.forward * speed); } Invoke("Disable", 0.3f); } else { transform.position = finalPos; } }
public void Attack() { //No need to check the closest target, since we should lock our attention to one troop at least as long as it's in the reachRadius if (Vector2.Distance(transform.position, currentTarget.position) < reachRad && currentTarget != gameObject.transform) { //Attack the target attackTimer -= Time.deltaTime; if (attackTimer <= 0) { List <Transform> enemyUnits = targetManager.FindAllTargetsWithinRadius(gameObject.transform, thisPlayer, attackRad + 0.1f); foreach (Transform unit in enemyUnits) { IDamageable healthScript = unit.GetComponent <IDamageable>(); if (healthScript != null) { healthScript.ApplyDamage(attackPower); } } attackTimer += attackPerSecond; AudioFW.Play("Unit_DarkK_Attack"); } } else if (Vector2.Distance(transform.position, currentTarget.position) < aggroRadius) { currentState = AIstate.Aggro; } else { currentState = AIstate.Navigate; //DeListen target death notification } }
void FixedUpdate() { damageCooldown = Mathf.Max(0.0f, damageCooldown - Time.deltaTime); if (!active) { return; } if (hitGameObject == null) { return; } if (damageCooldown <= 0.0f) { damageCooldown = maxDamageCooldown; } else { return; } IDamageable damageableObject = (IDamageable)hitGameObject.GetComponent(typeof(IDamageable)); if (damageableObject != null) { damageableObject.ApplyDamage(damageRate * maxDamageCooldown, spaceship.gameObject, gameObject.name + " is calling ApplyDamage()!"); } }
private void OnPlayerAttack(IDamageable damageable) { if (damageable.ApplyDamage(attackState.Body, attackForce) == false) { return; } attackState.Body.velocity /= onWrongAttackSlower; }
protected override void OnDamageableCollision(GameObject sourceObject, Collider collider, IDamageable damageable) { damageable.ApplyDamage(this && this.gameObject != null ? this.gameObject : null, collider, this.damage); if (!_piercing) { GameObject.Destroy(sourceObject); } }
private void OnCollisionEnter2D(Collision2D col) { IDamageable dam = col.gameObject.GetComponent <IDamageable>(); if (dam != null) { dam.ApplyDamage(this, damageValue); } }
private void OnPlayerAttack(IDamageable damageable) { if (damageable.ApplyDamage(_state.Rigidbody, _attackForce) == false) { return; } _state.Rigidbody.velocity /= 2; }
void OnCollisionEnter(Collision other) { if (other.collider.tag == "Target") { IDamageable damageable = other.collider.GetComponent <IDamageable>(); damageable.ApplyDamage(damageValue); Destroy(gameObject); } }
protected override void OnDamageableCollision(GameObject sourceObject, Collider collider, IDamageable damageable) { // The update method needs to know when the mine objects are exploding if (!_explodingProjectiles.Contains(sourceObject)) { _explodingProjectiles.Add(sourceObject); } damageable.ApplyDamage(this && this.gameObject != null ? this.gameObject : null, collider, this.damage); }
private void Attack() { if (canAttack) { shouldFollowPath = false; ResetAttack(); attackTarget.ApplyDamage(this, damagePerTick); } }
void OnCollisionEnter(Collision collision) { IDamageable idamageable = collision.gameObject.GetComponent <IDamageable>(); if (idamageable != null) { idamageable.ApplyDamage(-healPoint); Destroy(this.gameObject); } }
private void OnTriggerEnter(Collider other) { IDamageable ent = other.GetComponentInParent <IDamageable>(); if (null != ent) { ent.ApplyDamage(damage); Explode(); } }
void OnTriggerEnter(Collider other) { canDamage = null; canDamage = other.gameObject.GetComponent <IDamageable>(); if (null != canDamage) { canDamage.ApplyDamage(damage); } Explode(); }
private void OnCollisionEnter(Collision collision) { // Wenn das Objekt mit dem kollidiert wurde ein Compontent besitzt, dass das Interface IDamageable implementiert, so wird dieses Compontent zurückgegeben // und die "ApplyDamage()" Methode wird ausgeführt, wodurch das Objekt schaden bekomment. IDamageable damageableObject = (IDamageable)collision.gameObject.GetComponent(typeof(IDamageable)); if (damageableObject != null) { damageableObject.ApplyDamage(damageAmount); } }
private void Attack() { if (attackTarget != null) { if (canAttack) { attackTarget.ApplyDamage(this, damage); ResetAttack(); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <Bullet>() != null || other.CompareTag(_tagToAvoid)) { return; } _damageable = other.GetComponent <IDamageable>(); _damageable?.ApplyDamage(10); StartCoroutine(Explode()); }
public void OnTriggerEnter2D(Collider2D other) { // Debug.Log("Bullet Collided with " + other.gameObject.name); IDamageable damageable = other.GetComponent <IDamageable>(); if (damageable != null) { damageable.ApplyDamage(damage); } bulletManager.ReturnBullet(gameObject); }
private void OnCollisionEnter(Collision obj) { //obj.gameObject.GetComponent<Rigidbody>().AddForce(Vector3.up * damage / 2); IDamageable dam = obj.gameObject.GetComponent <IDamageable>(); if (dam != null) { dam.ApplyDamage(damage, Vector3.up); } }
void HandleDamage(IDamageable damageable, Vector3 position, Vector3 normal) { //If we hits something that can take damage then it's up to that object to show effects like particles etc if (damageable != null) { Vector3 direction = normal; direction.Normalize(); if (direction.magnitude != 1) { direction = Random.insideUnitSphere.normalized; } damageable.ApplyDamage(damage, transform.position, direction); } }
internal static void ApplyDamage(IDamageable first, IDamageable second) { KeyValuePair<Type, Type> pair = new KeyValuePair<Type, Type>(first.GetType(), second.GetType()); if (damages.ContainsKey(pair)) { KeyValuePair<int, int> damage = damages[pair]; bool firstKilled = first.ApplyDamage(damage.Key); bool secondKilled = second.ApplyDamage(damage.Value); if (firstKilled) MessageDispatcher.Post(new Kill(first)); if (secondKilled) MessageDispatcher.Post(new Kill(second)); } }
//actionで当たり判定検知はおかしいから書き直し private void OnCollisionStay(Collision collision) { if (collision.gameObject.tag == "Enemy") { return; } IDamageable idamageable = collision.gameObject.GetComponent <IDamageable>(); if (idamageable != null) { idamageable.ApplyDamage(bodyDamage); } }
void OnCollisionStay(Collision collision) { if (collision.gameObject.CompareTag("Obstacle")) { return; } IDamageable damageableObject = (IDamageable)collision.gameObject.GetComponent(typeof(IDamageable)); if (damageableObject != null) { damageableObject.ApplyDamage(damageRate, gameObject, "Calling from: " + gameObject.name); } }
private static void TryToApplyDamage(float damage, uint ownerID, Collider collider) { // TODO: FIX GC: This has 48.2 KB of garbage a frame // if there is no damageable interface - don't do anything else IDamageable damageable = collider.GetComponent <IDamageable>(); if (damageable == null) { return; } damageable.ApplyDamage(damage, ownerID); }
bool _body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { IDamageable hitObject = fixtureB.Body.UserData as IDamageable; _lifetimeTimer.Finish(); //Check if the object is even an IDamageable, and not the player if (hitObject == null || hitObject == Program.Objects.MainPlayer) { return(true); } hitObject.ApplyDamage(_projectileType.Damage); return(true); }
public void OnInteract(GameObject objectInteracting, object interactorType) { if (!trapSet || objectInteracting == null) { return; } if (!(interactorType is IDamageable)) { return; } IDamageable trapVictim = (IDamageable)interactorType; trapVictim.ApplyDamage(gameObject, trapDamage); trapSet = false; }
void Shoot () { // Reset the timer. timer = 0f; // Play the gun shot audioclip. gunAudio.Play (); // Enable the lights. gunLight.enabled = true; faceLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop (); gunParticles.Play (); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition (0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... (Modified By Me) if(Physics.Raycast (shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. IDamageable damage = shootHit.collider.GetComponent <IDamageable> (); // My Mod var onDamage = shootHit.collider.GetComponent<EnemyHealth>(); // My Mod // If the EnemyHealth component exist... if(damage != null && onDamage != null) // My Mod { // ... the enemy should take damage. onDamage.OnDamage((int)damage.ApplyDamage(damagePerShot, damage.Armor, shootHit.point), onDamage.gameObject); // My Mod } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition (1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range); } }
private void HandleMeleeAttack() { if (!isMeleeAttacking) { Animator.SetTrigger("Attack"); StartCoroutine(MeleeAttackAnimDelay()); Collider2D[] overlappedColliders = Physics2D.OverlapCircleAll(MeleeAttackOrigin.position, MeleeAttackRadius, layer); for (int i = 0; i < overlappedColliders.Length; i++) { IDamageable enemyAttributes = overlappedColliders[i].GetComponent <IDamageable> (); if (enemyAttributes != null) { enemyAttributes.ApplyDamage(MeleeDamage); } } } }