forked from JXPorter/OkitaUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cs
More file actions
177 lines (171 loc) · 3.44 KB
/
Example.cs
File metadata and controls
177 lines (171 loc) · 3.44 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public Vector3 pos = Vector3.zero;
public float speed = 0.1f;
void Start()
{
pos = transform.position;
// Members m = new Members ();
// m.FirstFunction ();
// Input.GetKey (KeyCode.A);
// Input.GetKey (KeyCode.W);
// Input.GetKey (KeyCode.S);
// Input.GetKey (KeyCode.D);
}
void Update()
{
// bool AKey = Input.GetKey (KeyCode.A);
// bool WKey = Input.GetKey (KeyCode.W);
// bool SKey = Input.GetKey (KeyCode.S);
// bool DKey = Input.GetKey (KeyCode.D);
//
// if (AKey) // 1st way of moving the cube.
// {
// pos.x = pos.x - speed;
// Debug.Log ("AKey");
// }
// if (WKey)
// {
// pos.z = pos.z + speed;
// Debug.Log ("WKey");
// }
// if (SKey)
// {
// pos.z = pos.z - speed;
// Debug.Log ("SKey");
// }
// if (DKey)
// {
// pos.x = pos.x + speed;
// //Debug.Log ("DKey");
// print ("DKey");
// }
// transform.position = pos;
transform.position += Movement(speed); // this uses my Movement function to change the position of whatever GameObject this script is attached to.
}
Vector3 Movement(float dist) //2nd way of moving the cube with a custom function that returns a Vector3 and takes a float as a parameter.
{
Vector3 vec = Vector3.zero; // vec is set to (0,0,0).
if (Input.GetKey(KeyCode.A)) // If Input is getting the A Key
{
vec.x -= dist; // then set the x position of the Vector 3 to be iterated by the dist float.
}
if(Input.GetKey(KeyCode.W))
{
vec.z += dist;
}
if(Input.GetKey(KeyCode.S))
{
vec.z -= dist;
}
if (Input.GetKey (KeyCode.D))
{
vec.x += dist;
}
return vec; // returns a Vector3 called vec
}
}
//// Original Code
//public class Example : MonoBehaviour
//{
// public Vector3 pos = Vector3.zero;
// public float speed;
//
// // Use this for initialization
// void Start()
// {
// Members m = new Members();
// m.FirstFunction();
// print(ImANumber());
// print(INeedANumber(1));
//// int val = INeedANumber(3) + INeedANumber(7);
//// print(val);
// int val = INeedTwoNumbers(3, 7);
// print(val);
// }
//
// bool NumbersAreTheSame(int a, int b)
// {
// if (a == b)
// {
// return true;
// } else
// {
// return false;
// }
// }
//
//
// int INeedTwoNumbers(int a, float b)
// {
// return a * (int)b;
// }
//
// int ImANumber()
// {
// return 3;
// }
//
// int INeedANumber(int number)
// {
// return number + 1;
// }
// float f = 0;
// void Update()
// {
// f += 0.25f;
// print(f);
//// print(Input.GetKey(KeyCode.A));
//// bool AKey = Input.GetKey(KeyCode.A);
//// bool SKey = Input.GetKey(KeyCode.S);
//// bool DKey = Input.GetKey(KeyCode.D);
//// bool WKey = Input.GetKey(KeyCode.W);
//// if (AKey)
//// {
//// pos.x = pos.x - 0.1f;
//// }
//// if (DKey)
//// {
//// pos.x = pos.x + 0.1f;
//// }
//// if (WKey)
//// {
//// pos.z = pos.z + 0.1f;
//// }
//// if (SKey)
//// {
//// pos.z = pos.z - 0.1f;
//// }
// transform.position += Movement(0.2f);
//// transform.position += Movement();
// }
//
// Vector3 Movement()
// {
// return new Vector3(0.1f, 0.2f, 0.3f);
// }
//
// Vector3 Movement(float dist)
// {
// Vector3 vec = Vector3.zero;
// if (Input.GetKey(KeyCode.A))
// {
// vec.x -= dist;
// }
// if (Input.GetKey(KeyCode.D))
// {
// vec.x += dist;
// }
// if (Input.GetKey(KeyCode.W))
// {
// vec.z += dist;
// }
// if (Input.GetKey(KeyCode.S))
// {
// vec.z -= dist;
// }
// return vec;
// }
//}