public void OnProjectileHit(ProjectileHitInfo hitInfo) { health -= hitInfo.Damage; hitInfo.Instigator.damageInflicted += hitInfo.Damage; if (health <= 0.0f) { //Zombie Dies hitInfo.Instigator.killCount++; Destroy(gameObject); } }
public void OnProjectileHit(ProjectileHitInfo hit) { strength--; if (strength == 0) { var go = GameObject.Instantiate(explosionPrefab, transform.position, Quaternion.identity); go.transform.localScale = Vector3.one * explosionScale; Collider[] explosionHits = Physics.OverlapSphere(transform.position, explosionRange); foreach (Collider explosionHit in explosionHits) { IExplosionHitListener explosionHitListener = explosionHit.GetComponent <IExplosionHitListener>(); float distance = Vector2.Distance(new Vector2(explosionHit.transform.position.x, explosionHit.transform.position.z), new Vector2(transform.position.x, transform.position.z)); explosionHitListener.OnExplosionHit(explosionDamage * distance / explosionRange); } GameObject.Destroy(this.gameObject); } }
void FixedUpdate() { if (Time.fixedTime >= spawnTime + Lifetime) { Debug.Log("Projectile timed out."); Destroy(gameObject); } Speed += Time.fixedDeltaTime * Acceleration; if (Speed <= 0f) { Debug.Log("Projectile speed dropped below 0."); Destroy(gameObject); } float distance = Time.fixedDeltaTime * Speed; RaycastHit hit; if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, distance, ~LayerMask.GetMask("Players"))) { transform.position = hit.point; ProjectileHitInfo hitInfo = new ProjectileHitInfo() { Damage = Damage, Instigator = Instigator }; IProjectileHitListener[] hitListeners = hit.collider.GetComponents <IProjectileHitListener>(); foreach (IProjectileHitListener listener in hitListeners) { listener.OnProjectileHit(hitInfo); } Destroy(gameObject); } else { transform.Translate(distance * Vector3.forward); } }
public void OnProjectileHit(ProjectileHitInfo hitInfo) { health -= hitInfo.Damage; }
bool factory(out ProjectileHitInfo hitInfo) { hitInfo = new ProjectileHitInfo(); return(hitInfo != null); }
private void onProjectileHitEnemy(ProjectileHitInfo projectileHitInfo) { // If a creature was hit, damage it if (projectileHitInfo.HitCreature != null && projectileHitInfo.HitCreature.IsAlive) { // Calculate the damage dealt based on the speed of the projectile. float finalDamage = projectileHitInfo.Speed * 2; // Remove the damage from the hit creature's health. projectileHitInfo.HitCreature.Health -= finalDamage; // Keep track of the dealt damage. if (projectileHitInfo.HitCreature.Player == Creature.Player) { changeLifetimeStat("FriendlyDamageDealt", finalDamage); } else { changeLifetimeStat("EnemyDamageDealt", finalDamage); } // If the creature is now dead, track the kill. if (!projectileHitInfo.HitCreature.IsAlive) { if (projectileHitInfo.HitCreature.Player == Creature.Player) { changeLifetimeStat("FriendlyKills", 1); } else { changeLifetimeStat("EnemyKills", 1); } } } // If this hit was closer than the previous hit, keep track of it. Vector3 targetPosition = (projectileHitInfo.TargetCreature != null) ? projectileHitInfo.TargetCreature.transform.position : projectileHitInfo.TargetPosition; float distanceFromTarget = Vector3.Distance(projectileHitInfo.HitPosition, targetPosition); if (distanceFromTarget < LifetimeStats["ClosestHit"]) { setLifetimeStat("ClosestHit", distanceFromTarget); } // Calculate the angle between the origin of the throw and the hit location, as well as the angle between the origin and the target. Vector2 originHitDirection = (new Vector2(projectileHitInfo.HitPosition.x, projectileHitInfo.HitPosition.z) - new Vector2(projectileHitInfo.OriginPosition.x, projectileHitInfo.OriginPosition.z)).normalized; Vector2 originTargetDirection = (new Vector2(targetPosition.x, targetPosition.z) - new Vector2(projectileHitInfo.OriginPosition.x, projectileHitInfo.OriginPosition.z)).normalized; Debug.DrawLine(projectileHitInfo.OriginPosition, projectileHitInfo.HitPosition, Color.green, 10); Debug.DrawLine(projectileHitInfo.OriginPosition, targetPosition, Color.blue, 10); // Calculate the dot product between the desired throw and the actual throw. If this value is higher than the current best, set the current best to it. float dotProduct = Vector2.Dot(originHitDirection, originTargetDirection); if (dotProduct > LifetimeStats["BestAngle"]) { setLifetimeStat("BestAngle", dotProduct); } // Increment the collided shots counter, as the shot hit something. collidedShots++; }