2
|
1 using UnityEngine;
|
|
2 using System.Collections;
|
|
3
|
|
4 public class smartballscript : MonoBehaviour {
|
|
5 // public static int n = 1;
|
|
6 float power = 0f;
|
|
7 bool flg = true;
|
|
8 GameObject[] cubes = new GameObject[5];
|
|
9 // Vector3[] moves = new Vector3[5];
|
|
10
|
|
11 // Use this for initialization
|
|
12 void Start () {
|
|
13 // GameObject[] goals = GameObject.FindGameObjectsWithTag ("goal");
|
|
14 // int n = 0;
|
|
15 // foreach(GameObject obj in goals){
|
|
16 // obj.GetComponent<Renderer> ().material.shader =
|
|
17 // Shader.Find ("Transparent/Diffuse");
|
|
18 // obj.GetComponent<Renderer>().material.color =
|
|
19 // new Color(0f, 0.15f * n, 1f - 0.15f * n++, 0.5f);
|
|
20 // }
|
|
21 // GameObject[] ob_cubes = GameObject.FindGameObjectsWithTag ("ob_cube");
|
|
22 // foreach (GameObject obj in ob_cubes) {
|
|
23 // Vector3 move = obj.transform.position;
|
|
24 // AnimationClip clip = new AnimationClip ();
|
|
25 // Keyframe[] keysX = new Keyframe[2];
|
|
26 // keysX [0] = new Keyframe (0f, move.x - 3);
|
|
27 // keysX [1] = new Keyframe (2f, move.x + 3);
|
|
28 // AnimationCurve curveX = new AnimationCurve (keysX);
|
|
29 // clip.SetCurve ("", typeof(Transform), "localPosition.x", curveX);
|
|
30 // clip.wrapMode = WrapMode.PingPong;
|
|
31 //
|
|
32 // Keyframe[] keysY = new Keyframe[2];
|
|
33 // keysY [0] = new Keyframe (0f, move.y);
|
|
34 // keysY [1] = new Keyframe (2f, move.y);
|
|
35 // AnimationCurve curveY = new AnimationCurve (keysY);
|
|
36 // clip.SetCurve ("", typeof(Transform), "localPosition.y", curveY);
|
|
37 //
|
|
38 // Keyframe[] keysZ = new Keyframe[2];
|
|
39 // keysZ [0] = new Keyframe (0f, move.z);
|
|
40 // keysZ [1] = new Keyframe (2f, move.z);
|
|
41 // AnimationCurve curveZ = new AnimationCurve (keysZ);
|
|
42 // clip.SetCurve ("", typeof(Transform), "localPosition.z", curveZ);
|
|
43 //
|
|
44 // obj.GetComponent<Animation>().AddClip (clip, "clip1");
|
|
45 // obj.GetComponent<Animation>().Play ("clip1");
|
|
46 // }
|
|
47 // moves [0] = new Vector3 (0f, 1f, 0f);
|
|
48 // moves [1] = new Vector3 (-3f, 1f, 5f);
|
|
49 // moves [2] = new Vector3 (3f, 1f, 5f);
|
|
50 // moves [3] = new Vector3 (-3f, 1f, 5f);
|
|
51 // moves [4] = new Vector3 (3f, 1f, -3f);
|
|
52 // for (int i = 0; i < 5; i++){
|
|
53 // cubes[i] = GameObject.Find("BoardCube" + i);
|
|
54 // Vector3 move = cubes[i].transform.position;
|
|
55 // AnimationClip clip = new AnimationClip();
|
|
56 // Keyframe[] keysX = new Keyframe[2];
|
|
57 // keysX[0] = new Keyframe(0f, move.x - 3);
|
|
58 // keysX[1] = new Keyframe(i + 1f,move.x + 3);
|
|
59 // AnimationCurve curveX = new AnimationCurve(keysX);
|
|
60 // clip.SetCurve("", typeof(Transform), "localPosition.x", curveX);
|
|
61 // clip.wrapMode = WrapMode.PingPong;
|
|
62 //
|
|
63 // Keyframe[] keysY = new Keyframe[2];
|
|
64 // keysY[0] = new Keyframe(0f, move.y);
|
|
65 // keysY[1] = new Keyframe(i + 1f, move.y);
|
|
66 // AnimationCurve curveY = new AnimationCurve(keysY);
|
|
67 // clip.SetCurve("", typeof(Transform), "localPosition.y", curveY);
|
|
68 //
|
|
69 // Keyframe[] keysZ = new Keyframe[2];
|
|
70 // keysZ[0] = new Keyframe(0f, move.z);
|
|
71 // keysZ[1] = new Keyframe(i + 1f, move.z);
|
|
72 // AnimationCurve curveZ = new AnimationCurve(keysZ);
|
|
73 // clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);
|
|
74 //
|
|
75 // cubes[i].GetComponent<Animation>().AddClip(clip, "clip1");
|
|
76 // cubes[i].GetComponent<Animation>().Play("clip1");
|
|
77 // }
|
|
78 }
|
|
79
|
|
80 // Update is called once per frame
|
|
81 void Update () {
|
|
82 MoveCube ();
|
|
83 GetComponent<Rigidbody> ().AddForce (0f, 0f, -10f);
|
|
84 if (flg){
|
|
85 if (Input.GetKey (KeyCode.Space)) {
|
|
86 power += 0.01f;
|
|
87 if (power > 1f) {
|
|
88 power = 1f;
|
|
89 }
|
|
90 GetComponent<Renderer> ().material.color = new Color (1f, power, 0f);
|
|
91 }
|
|
92 }
|
|
93 if (Input.GetKeyUp(KeyCode.Space)){
|
|
94 GetComponent<Rigidbody> ().AddForce (new Vector3 (0f, 0f, power * 2500f));
|
|
95 power = 0f;
|
|
96 GetComponent<Renderer> ().material.color = Color.red;
|
|
97 flg = false;
|
|
98 }
|
|
99 if((transform.position.y > 10)||(transform.position.y < -10)){
|
|
100 GetComponent<Rigidbody> ().velocity = Vector3.zero;
|
|
101 transform.position = new Vector3 (9f, 0.5f, -13f);
|
|
102 }
|
|
103 }
|
|
104
|
|
105
|
|
106 void OnCollisionEnter(Collision collision){
|
|
107 if (collision.gameObject.tag == "ob_cube") {
|
|
108 Behaviour b = (Behaviour)collision.gameObject.GetComponent ("Halo");
|
|
109 b.enabled = true;
|
|
110 }
|
|
111 if (collision.gameObject.name == "Cube (3)") {
|
|
112 // transform.position = new Vector3 (9f, 0.5f, -13f);
|
|
113 flg = true;
|
|
114 // Application.LoadLevel ("Sence1");
|
|
115 }
|
|
116 if (collision.gameObject.name == "Cube (13)") {
|
|
117 flg = true;
|
|
118 }
|
|
119 }
|
|
120
|
|
121 void OnCollisionExit(Collision collision){
|
|
122 if (collision.gameObject.tag == "ob_cube"){
|
|
123 Behaviour b = (Behaviour)collision.gameObject.GetComponent ("Halo");
|
|
124 b.enabled = false;
|
|
125 Vector3 v = GetComponent<Rigidbody> ().velocity;
|
|
126 if (v.magnitude < 15){
|
|
127 v *= 2.0f;
|
|
128 if (v.magnitude < 5) {
|
|
129 v *= 2.0f;
|
|
130 }
|
|
131 GetComponent<Rigidbody>().velocity = v;
|
|
132 }
|
|
133 }
|
|
134 if (collision.gameObject.tag == "ob_wall"){
|
|
135 Vector3 v = GetComponent<Rigidbody> ().velocity;
|
|
136 if (v.magnitude < 20){
|
|
137 v *= 1.5f;
|
|
138 if (v.magnitude < 5){
|
|
139 v *= 2.0f;
|
|
140 }
|
|
141 GetComponent<Rigidbody>().velocity = v;
|
|
142 }
|
|
143 }
|
|
144 }
|
|
145
|
|
146 void MoveCube(){
|
|
147 GameObject[] ob_cubes = GameObject.FindGameObjectsWithTag ("ob_cube");
|
|
148 foreach (GameObject obj in ob_cubes) {
|
|
149 if (obj.gameObject.name != "BoardCube5") {
|
|
150 if (obj.gameObject.name == "BoardCube0") {
|
|
151 obj.transform.Rotate (new Vector3 (0f, -7f, 0f));
|
|
152 } else {
|
|
153 obj.transform.Rotate (new Vector3 (0f, 7f, 0f));
|
|
154 }
|
|
155 }
|
|
156 }
|
|
157 // for(int i = 0; i < 5; i++){
|
|
158 // cubes [i].transform.Rotate (new Vector3 (0f, 2.5f, 0f));
|
|
159 // }
|
|
160 }
|
|
161
|
|
162 void OnTriggerEnter(Collider collider){
|
|
163 if (collider.gameObject.tag == "goal"){
|
|
164 GetComponent<Rigidbody> ().velocity = Vector3.zero;
|
|
165 GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
|
|
166 // if (collider.name == "Cylinder0") {
|
|
167 // Application.LoadLevel ("50");
|
|
168 // }if (collider.name == "Cylinder1") {
|
|
169 // Application.LoadLevel ("200");
|
|
170 // }if (collider.name == "Cylinder2") {
|
|
171 // Application.LoadLevel ("400");
|
|
172 // }if (collider.name == "Cylinder3") {
|
|
173 // Application.LoadLevel ("300");
|
|
174 // }if (collider.name == "Cylinder4") {
|
|
175 // Application.LoadLevel ("500");
|
|
176 // }if (collider.name == "Cylinder5") {
|
|
177 // Application.LoadLevel ("100");
|
|
178 // }
|
|
179 // GameObject[] objs = GameObject.FindGameObjectsWithTag ("goal");
|
|
180 // int n = 1;
|
|
181 // foreach(GameObject obj in objs){
|
|
182 // for (int i = 0; i < 5; i++){
|
|
183 // GameObject obj = GameObject.Find ("Cylinder" + i);
|
|
184 // if (obj == collider.gameObject) {
|
|
185 // GameObject.Find ("GUI Text").GetComponent<GUIText> ().text =
|
|
186 // "point:" + (n * 100);
|
|
187 // n *= 100;
|
|
188 // ParticleSystem ps = (ParticleSystem)GameObject.Find("Cylinder" + i).
|
|
189 // GetComponent ("ParticleSystem");
|
|
190 // }
|
|
191 // n++;
|
|
192 // }
|
|
193 }
|
|
194 }
|
|
195 void OnTriggerExit(Collider collider){
|
|
196 if (collider.name == "Cylinder0") {
|
|
197 Application.LoadLevel ("50");
|
|
198 }if (collider.name == "Cylinder1") {
|
|
199 Application.LoadLevel ("200");
|
|
200 }if (collider.name == "Cylinder2") {
|
|
201 Application.LoadLevel ("400");
|
|
202 }if (collider.name == "Cylinder3") {
|
|
203 Application.LoadLevel ("300");
|
|
204 }if (collider.name == "Cylinder4") {
|
|
205 Application.LoadLevel ("500");
|
|
206 }if (collider.name == "Cylinder5") {
|
|
207 Application.LoadLevel ("100");
|
|
208 }
|
|
209 }
|
|
210 }
|