Пример #1
0
    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();
        }
    }
Пример #2
0
 private void OnHitEvent(HitableComponent hc)
 {
     StartCoroutine(WaitAndDestroy());
 }
Пример #3
0
 // Start is called before the first frame update
 void Awake()
 {
     rb              = GetComponent <Rigidbody2D>();
     hc              = GetComponent <HitableComponent>();
     hc.GotHitEvent += OnHitEvent;
 }
Пример #4
0
 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());
 }
Пример #5
0
 private void Awake()
 {
     hc              = GetComponent <HitableComponent>();
     hc.GotHitEvent += OnHitEvent;
 }