Spikes.cs 480 Bytes
Newer Older
Unknown's avatar
Unknown committed
1
2
3
4
5
6
7
8
9
10
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent (typeof (BoxCollider2D))]
public class Spikes : MonoBehaviour {

    [SerializeField] private int m_Damage = 1;

    void OnCollisionEnter2D(Collision2D col2D){
Unknown's avatar
Unknown committed
11
        if(col2D.transform.gameObject.tag.Equals("Player") || col2D.transform.gameObject.tag.Equals("Enemy")){
Unknown's avatar
Unknown committed
12
13
14
15
16
            Life l = col2D.transform.GetComponent<Life>();
            l.Damage(m_Damage);
        }
    }

Unknown's avatar
Unknown committed
17
}