ProjektilController.cs 580 Bytes
Newer Older
Markus Schlösser's avatar
Markus Schlösser committed
1
using UnityEngine;
Jan Meissner's avatar
Jan Meissner committed
2

3
public class ProjektilController : MonoBehaviour, IResetable {
Markus Schlösser's avatar
Markus Schlösser committed
4

5
6
	public bool ignoreEnviroment;

Markus Schlösser's avatar
Markus Schlösser committed
7
8
9
10
11
12
13
	private const float MAX_LIFETIME = 15.0f;

	private float lifetime;

	private void Update() {
		if (lifetime > MAX_LIFETIME) {
			Destroy(gameObject);
Markus Schlösser's avatar
Markus Schlösser committed
14
		} 
Markus Schlösser's avatar
Markus Schlösser committed
15
16

		lifetime += Time.deltaTime;
Jan Meissner's avatar
Jan Meissner committed
17
	}
Markus Schlösser's avatar
Markus Schlösser committed
18

Markus Schlösser's avatar
Markus Schlösser committed
19
	private void OnTriggerEnter2D(Collider2D other) {
20
21
22
		// Don't destroy on contact with enviroment if set to ignore
		if (other.gameObject.layer == 12 && ignoreEnviroment) return;

Jan Meissner's avatar
Jan Meissner committed
23
24
		Destroy(gameObject);
	}
25
26
27
28

	public void ResetToLevelBegin() {
		Destroy(gameObject);
	}
Jan Meissner's avatar
Jan Meissner committed
29
}