/
PlaneCollider.cs
77 lines (57 loc) · 1.7 KB
/
PlaneCollider.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*COMP3064-Assignment1
* Project Name: Air Flight
* File Name: Sky Controller
* Author: Heng Wang
* Student ID: 100976892
* Last Modified by: Heng Wang
* Last Modified Date: Oct 27, 2016
* */
using UnityEngine;
using System.Collections;
public class PlaneCollider : MonoBehaviour {
[SerializeField]
GameObject explosion = null;
//When collide with other object
void OnTriggerEnter2D(Collider2D other){
//Collide with points
if (other.gameObject.tag == "point") {
Player.Instance.Points += 10;
PointsController po = other.gameObject.GetComponent<PointsController> ();
//Reset the point object
if (po != null) {
po.Reset ();
}
AudioSource asrc = other.gameObject.GetComponent<AudioSource> ();
//Play collection sound
if (asrc != null) {
asrc.Play ();
}
} //Collide with ememy
else if (other.gameObject.tag == "enemy") {
Player.Instance.Health -= 1;
EnemyController en = other.gameObject.GetComponent<EnemyController> ();
//Show explosion and reset enemy
if (en != null) {
GameObject ex = Instantiate (explosion);
ex.transform.position = en.transform.position;
en.Reset ();
}
//
AudioSource asrc =other.gameObject.GetComponent<AudioSource> ();
//Play explosion sound
if (asrc != null) {
asrc.Play ();
}
}else if (other.gameObject.tag == "power") {
//Points add 15
Player.Instance.Points += 15;
//Health add 1
Player.Instance.Health += 1;
//hide power object
other.gameObject.SetActive (false);
//Increase plane speed
PlaneController plane = gameObject.GetComponent<PlaneController> ();
plane.PowerUpSpeed ();
}
}
}