-
Notifications
You must be signed in to change notification settings - Fork 0
/
EgoBall.cs
111 lines (69 loc) · 2.04 KB
/
EgoBall.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EgoBall : MonoBehaviour {
public GameObject effect;
private Vector3 initPosition;
public float rage;
public int turno, maxTurno;
private int hits, score1, score2;
private bool hit1, hit2;
private Rigidbody2D rb;
private Animator anim;
void Awake () {
initPosition = transform.position;
rb = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
MaxTurno (2);
InitialProperties ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D (Collider2D collision) {
if (GetComponent <CircleCollider2D> ().IsTouchingLayers (LayerMask.GetMask ("Player"))) {
if (collision.gameObject.name.StartsWith ("Collider1") && !hit1) {
rb.velocity = FindObjectOfType<Directions> ().GetDirection ("Right", hits) * rage;
hit1 = true;
hit2 = false;
FindObjectOfType<AudioManager> ().PlayAudio ("Marico1");
} else if (collision.gameObject.name.StartsWith ("Collider2") && !hit2) {
rb.velocity = FindObjectOfType<Directions> ().GetDirection ("Left", hits) * rage;
hit1 = false;
hit2 = true;
FindObjectOfType<AudioManager> ().PlayAudio ("Marico2");
}
Instantiate (effect, transform.position, transform.rotation);
anim.SetBool ("RotateRight", hit1);
anim.SetBool ("RotateLeft", hit2);
if (hits == 0)
hits++;
rage += 0.5f;
}
if (GetComponent <CircleCollider2D> ().IsTouchingLayers (LayerMask.GetMask ("Walls"))) {
if (hit1)
FindObjectOfType<Score> ().SetScore (1);
else if (hit2)
FindObjectOfType<Score> ().SetScore (2);
rb.velocity = Vector2.zero;
InitialProperties ();
transform.position = initPosition;
}
}
void InitialProperties () {
rage = 12f;
hits = 0;
hit1 = false;
hit2 = false;
anim.SetBool ("RotateRight", hit1);
anim.SetBool ("RotateLeft", hit2);
if (turno >= maxTurno) {
turno = 0;
initPosition.x *= -1;
}
turno++;
}
public void MaxTurno (int n) {
maxTurno = n;
}
}