public void Fire(Vector3 firingLocation, Vector3 direction, Vector3 fxLocation) { Debug.Log("PierceBulletEffect: Firing!"); RaycastHit[] targets = Physics.RaycastAll(firingLocation, direction, maxDistance); for (int i = 0; i < targets.Length; i++) { IDamageComponent target = targets[i].collider.GetComponent <IDamageComponent>(); if (target != null) { target.TakeDamage(damage); } } if (targets.Length > 0) { if (BulletHit != null) { BulletHit(); } } Debug.Log("PierceBulletEffect: Firing line from " + firingLocation + " to " + firingLocation + direction.normalized * maxDistance); line.SetPosition(0, fxLocation); line.SetPosition(1, firingLocation + direction.normalized * maxDistance); StartCoroutine(StartFireEffect()); }
public override void Destroy() { CollisionComponent.OnCollision -= Collided; CollisionComponent = null; DamageComponent = null; base.Destroy(); }
protected virtual void OnHit(IDamageComponent target) { target.TakeDamage(damage); gameObject.SetActive(false); if (BulletHit != null) { BulletHit(); } }
public override void Initialize() { //Subscribe to our ICollisionComponent. CollisionComponent = ParentGameObject.GetComponent<ICollisionComponent>(); CollisionComponent.OnCollision += Collided; //Get a reference to our damage component. DamageComponent = ParentGameObject.GetComponent<IDamageComponent>(); base.Initialize(); }
private void OnTriggerEnter(Collider other) { Debug.Log("FastBulletEffect: I'm hitting something!"); IDamageComponent target = other.gameObject.GetComponent <IDamageComponent>(); if (target != null) { Debug.Log("FastBulletEffect: It was the IDamageComponent of " + other.name); OnHit(target); } }
void OnCollisionEnter(Collision collision) { Debug.Log("EnemyScript: I'm colliding with something"); IDamageComponent player = collision.gameObject.GetComponent <IDamageComponent>(); if (player != null) { Debug.Log("EnemyScript: It was the player, attacking!"); player.TakeDamage(attackDamage); } }
public override void Initialize() { //Subscribe to our ICollisionComponent. CollisionComponent = ParentGameObject.GetComponent <ICollisionComponent>(); CollisionComponent.OnCollision += Collided; //Get a reference to our damage component. DamageComponent = ParentGameObject.GetComponent <IDamageComponent>(); base.Initialize(); }
public override void Initialize() { damageComponent = ParentGameObject.GetComponent<IDamageComponent>(); base.Initialize(); }