-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoonScript.cs
113 lines (94 loc) · 3.16 KB
/
MoonScript.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
111
112
113
using UnityEngine;
using System.Collections;
public class MoonScript : MonoBehaviour {
public float impulse_strength;
public bool to_launch = false;
Vector3 offset;
Vector3 screenPoint;
Vector3 force = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 original_position;
Quaternion original_rotation;
/* 0 - none
* 1 - circular
* 2 - elliptical
* 3 - impact */
private int current_status;
// Use this for initialization
void Start () {
//transform.position = new Vector3(transform.position.x, transform.position.y, GameObject.Find("Controller").GetComponent<ControllerScript>().universal_z);
original_position = transform.position;
original_rotation = transform.rotation;
rigidbody.isKinematic = true;
current_status = 0;
}
// Update is called once per frame
void Update () {
if (to_launch)
{
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
//pos.z = GameObject.Find("Controller").GetComponent<ControllerScript>().universal_z;
transform.position = pos;
}
}
void OnBecameInvisible()
{
if(!to_launch)
{
TextMesh text = GameObject.Find("InfoText").GetComponent<TextMesh>();
text.text = "Fail!";
updatePoints();
text.animation.Play("InformationAnimation");
GameObject.Destroy(this.gameObject);
}
}
IEnumerator WaitForAnimation(float wait_time)
{
yield return new WaitForSeconds(wait_time);
ReloadState();
}
public void ReloadState()
{
to_launch = true;
transform.position = original_position;
transform.rotation = original_rotation;
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
rigidbody.isKinematic = true;
}
void OnMouseDown()
{
to_launch = false;
rigidbody.isKinematic = false;
}
void OnMouseUp()
{
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
Vector3 distance = transform.position - mousePosition;
distance.z = 0;
force = distance*impulse_strength;
rigidbody.AddForce(force, ForceMode.Impulse);
GameObject.Find("Controller").GetComponent<ControllerScript>().CreateNewPlanet();
}
/*
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint); //+ offset;
transform.position = curPosition;
}
*/
/*
void OnTriggerEnter ( Collider other) {
Debug.Log("Collision");
}*/
void setStatus(int new_status){
current_status = new_status;
}
void updatePoints(){
//GameObject.Find("Controller").GetComponent<ControllerScript>().points -= (rigidbody.mass*GameObject.Find("Controller").GetComponent<ControllerScript>().planet_points*GameObject.Find("Controller").GetComponent<ControllerScript>().lost_planet_factor);
// if (GameObject.Find("Controller").GetComponent<ControllerScript>().points < 0)
// GameObject.Find("Controller").GetComponent<ControllerScript>().points = 0;
// Debug.Log("points:" + GameObject.Find("Controller").GetComponent<ControllerScript>().points);
}
}