-
Notifications
You must be signed in to change notification settings - Fork 2
/
collisionDetector.cs
40 lines (36 loc) · 1.07 KB
/
collisionDetector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using UnityEngine;
using System.Collections;
public class collisionDetector : MonoBehaviour {
public Vector2 direction;
public Vector2 result;
public Vector2 position;
public bool collision;
public bool cantMove;
[SerializeField]GameController gctrl;
void Start(){
StartCoroutine (wait());
}
void OnTriggerEnter(Collider other) {
//
//the collider doesn't work on players, just the colliders they generate
if (other.gameObject.tag == "Player"||other.gameObject.tag == "damage"||other.gameObject.tag == "pickup")
return;
//this might need to change!
//also, using layers is a better idea!
//
print ("collision");
collision = true;
if (other.gameObject.GetComponent<collisionDetector> () != null) {
print ("collision with other player");
collisionDetector otherMovement = other.gameObject.GetComponent<collisionDetector> ();
result = otherMovement.direction;
} else {
print ("collision with still object");
result = direction * -1;
}
}
IEnumerator wait(){
yield return new WaitForSeconds (0.02f);
Destroy (this.gameObject);
}
}