private void OnCollisionEnter2D(Collision2D collision) { float force = 50f; HitableComponent hc = collision.gameObject.GetComponent <HitableComponent>(); if (hc != null && hc.gameObject.GetComponent <Rigidbody2D>()) { SoundLibrary.Instance.audioSource.PlayOneShot(SoundLibrary.Instance.SwordSounds[0], 0.7f); hc.Hit(); Vector2 dir = collision.transform.position - transform.position; dir = dir.normalized; hc.GetComponent <Rigidbody2D>().AddForce(dir * force, ForceMode2D.Impulse); } else if (hc != null) { hc.Hit(); } }
private void OnHitEvent(HitableComponent hc) { StartCoroutine(WaitAndDestroy()); }
// Start is called before the first frame update void Awake() { rb = GetComponent <Rigidbody2D>(); hc = GetComponent <HitableComponent>(); hc.GotHitEvent += OnHitEvent; }
private void OnHitEvent(HitableComponent hc) { Instantiate(dustParticle, transform.position, dustParticle.transform.rotation); SoundLibrary.Instance.audioSource.PlayOneShot(SoundLibrary.Instance.WoodSounds[Random.Range(0, SoundLibrary.Instance.WoodSounds.Length)]); StartCoroutine(GetDestroyed()); }
private void Awake() { hc = GetComponent <HitableComponent>(); hc.GotHitEvent += OnHitEvent; }