/
SphereController.cs
53 lines (44 loc) · 1.3 KB
/
SphereController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereController : MonoBehaviour {
private Rigidbody rb;
public float speed;
public GUIText score;
public GUIText win;
private int targetHit;
private void showText() {
score.text = "Point : "+targetHit.ToString ();
if (targetHit >= 13) {
win.text = "Congratulations...!\n You Wiiin...!";
}
}
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
targetHit = 0;
win.text = "";
showText ();
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
float horizontalValue = Input.GetAxis ("Horizontal");
float verticalValue = Input.GetAxis ("Vertical");
Vector3 v3 = new Vector3 (horizontalValue, 0.0f, verticalValue);
rb.AddForce (v3 * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider obj) {
if (obj.gameObject.tag == "hisoka_target") {
GameObject FlareRsc = Resources.Load ("Flare") as GameObject;
GameObject FlareObj = Instantiate (FlareRsc) as GameObject;
FlareObj.transform.position = transform.position;
//After ball hit the cube, we hide the cube and destroy FlareObj
Destroy(FlareObj, 7);
obj.gameObject.SetActive (false);
targetHit++; //Increment by one when one cube is hit
showText();
}
}
}