|
3 | 3 |
|
4 | 4 | public class CharacterControls : MonoBehaviour { |
5 | 5 |
|
6 | | - |
| 6 | + public enum CONTROL_TYPE {Gamepad, Mouse}; |
| 7 | + |
| 8 | + public CONTROL_TYPE controlType; |
7 | 9 | private Rigidbody rb; |
8 | 10 | private float squaredLockSpeed; |
9 | 11 | private float squaredMagnitude; |
@@ -34,40 +36,92 @@ void Awake(){ |
34 | 36 | // Update is called once per frame |
35 | 37 | void Update () { |
36 | 38 |
|
37 | | - ray = Camera.main.ScreenPointToRay(Input.mousePosition); |
38 | | - |
39 | | - if (Physics.Raycast(ray, out rayHit)) |
40 | | - { |
41 | | - Transform tempTran = transform; |
42 | | - tempTran.LookAt(rayHit.point); |
43 | | - transform.rotation = Quaternion.Euler(0, tempTran.rotation.eulerAngles.y, 0); |
44 | | - } |
| 39 | + //TO DO: This control type may be a hack |
| 40 | + if (controlType == CONTROL_TYPE.Mouse) |
| 41 | + { |
| 42 | + ray = Camera.main.ScreenPointToRay(Input.mousePosition); |
| 43 | + |
| 44 | + if (Physics.Raycast(ray, out rayHit)) |
| 45 | + { |
| 46 | + Transform tempTran = transform; |
| 47 | + tempTran.LookAt(rayHit.point); |
| 48 | + transform.rotation = Quaternion.Euler(0, tempTran.rotation.eulerAngles.y, 0); |
| 49 | + } |
| 50 | + |
| 51 | + if (Input.GetButtonDown("Movement")){ |
| 52 | + SetMoveTowards(Input.mousePosition); |
| 53 | + } |
45 | 54 |
|
46 | | - if (Input.GetButtonDown("Movement")){ |
47 | | - SetMoveTowards(Input.mousePosition); |
48 | | - } |
49 | 55 |
|
50 | | - if (Input.GetButtonDown("Fire1")){ |
51 | | - if (GUIUtility.hotControl == 0){ |
52 | | - spellSelector.CastSpell(lockStatus.currentSpell); |
| 56 | + if (Input.GetButtonDown("Fire1")){ |
| 57 | + if (GUIUtility.hotControl == 0){ |
| 58 | + spellSelector.CastSpell(lockStatus.currentSpell); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if (Input.GetButtonDown("Spell1")){ |
| 63 | + CastSpell1(); |
| 64 | + } |
| 65 | + else if (Input.GetButtonDown("Spell2")){ |
| 66 | + CastSpell2(); |
53 | 67 | } |
| 68 | + else if (Input.GetButtonDown("Spell3")){ |
| 69 | + CastSpell3(); |
| 70 | + } |
| 71 | + else if (Input.GetButtonDown("Spell4")){ |
| 72 | + CastSpell4(); |
| 73 | + } |
| 74 | + else if (Input.GetButtonDown ("Spell5")){ |
| 75 | + CastSpell5(); |
| 76 | + } |
| 77 | + |
54 | 78 | } |
55 | 79 |
|
56 | | - if (Input.GetButtonDown("Spell1")){ |
57 | | - CastSpell1(); |
58 | | - } |
59 | | - else if (Input.GetButtonDown("Spell2")){ |
60 | | - CastSpell2(); |
61 | | - } |
62 | | - else if (Input.GetButtonDown("Spell3")){ |
63 | | - CastSpell3(); |
64 | | - } |
65 | | - else if (Input.GetButtonDown("Spell4")){ |
66 | | - CastSpell4(); |
67 | | - } |
68 | | - else if (Input.GetButtonDown ("Spell5")){ |
69 | | - CastSpell5(); |
| 80 | + if (controlType == CONTROL_TYPE.Gamepad) |
| 81 | + { |
| 82 | + |
| 83 | + if (Input.GetAxis("Horizontal") != 0) |
| 84 | + { |
| 85 | + float axisValue = Input.GetAxis("Horizontal"); |
| 86 | + rigidbody.AddForce(new Vector3(lockSpeed*axisValue, 0, 0)); |
| 87 | + } |
| 88 | + |
| 89 | + if (Input.GetAxis("Vertical") != 0) |
| 90 | + { |
| 91 | + float axisValue = Input.GetAxis("Vertical"); |
| 92 | + rigidbody.AddForce(new Vector3(0, 0, lockSpeed*axisValue)); |
| 93 | + } |
| 94 | + //TODO: Fixed this shit |
| 95 | + if (Input.GetAxis("HorizontalLook") != 0 || Input.GetAxis("VerticalLook") != 0) |
| 96 | + { |
| 97 | + float xAxisValue = Input.GetAxis("HorizontalLook"); |
| 98 | + float yAxisValue = Input.GetAxis("VerticalLook"); |
| 99 | + float radian = Mathf.Asin(xAxisValue); |
| 100 | + float degrees = radian * Mathf.Rad2Deg; |
| 101 | + if (yAxisValue > 0) |
| 102 | + degrees = 360 - degrees; |
| 103 | + |
| 104 | + Debug.Log(degrees); |
| 105 | + Quaternion direction = Quaternion.Euler(0, degrees, 0); |
| 106 | + transform.rotation = direction; |
| 107 | + |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + if (Input.GetButtonDown("Fire2")){ |
| 112 | + CastSpell1(); |
| 113 | + } |
| 114 | + |
| 115 | + if (Input.GetButtonDown("Fire3")){ |
| 116 | + CastSpell2(); |
| 117 | + } |
| 118 | + |
| 119 | + if (Input.GetButtonDown("Fire4")){ |
| 120 | + CastSpell3(); |
| 121 | + } |
70 | 122 | } |
| 123 | + |
| 124 | + |
71 | 125 | /* |
72 | 126 | if (Input.GetKey(KeyCode.D)) |
73 | 127 | rigidbody.AddForce(new Vector3(lockSpeed, 0, 0)); |
@@ -95,8 +149,8 @@ void SetLockSpeed(float lockSpeed) |
95 | 149 | void FixedUpdate(){ |
96 | 150 |
|
97 | 151 | //Moves the lock towards the last clicked point |
98 | | - if (!((moveTowards - transform.position).sqrMagnitude < 1 )) |
99 | | - MoveTowards(); |
| 152 | + //if (!((moveTowards - transform.position).sqrMagnitude < 1 )) |
| 153 | + // MoveTowards(); |
100 | 154 |
|
101 | 155 |
|
102 | 156 | //Limits the velocity of the lock to it's max speed |
@@ -132,32 +186,66 @@ private void MoveTowards() |
132 | 186 |
|
133 | 187 | //----------------------Spell Casters------------------------// |
134 | 188 |
|
| 189 | + |
135 | 190 | void CastSpell1(){ |
136 | | - lockStatus.currentSpell = (int)SPELLS.Fireball; |
137 | | - gui.SetProjectileCursor(); |
138 | | - if (Input.GetKey(KeyCode.LeftAlt)) |
| 191 | + |
| 192 | + if (controlType == CONTROL_TYPE.Mouse) |
| 193 | + { |
| 194 | + lockStatus.currentSpell = (int)SPELLS.Fireball; |
| 195 | + gui.SetProjectileCursor(); |
| 196 | + if (Input.GetKey(KeyCode.LeftAlt)) |
| 197 | + spellSelector.smartCast = true; |
| 198 | + } |
| 199 | + else if (controlType == CONTROL_TYPE.Gamepad) |
| 200 | + { |
| 201 | + lockStatus.currentSpell = (int)SPELLS.Fireball; |
139 | 202 | spellSelector.smartCast = true; |
| 203 | + } |
140 | 204 | } |
141 | 205 |
|
142 | 206 | void CastSpell2(){ |
143 | | - lockStatus.currentSpell = (int)SPELLS.Fireblast; |
144 | | - gui.SetProjectileCursor(); |
145 | | - if (Input.GetKey(KeyCode.LeftAlt)) |
| 207 | + if (controlType == CONTROL_TYPE.Mouse) |
| 208 | + { |
| 209 | + lockStatus.currentSpell = (int)SPELLS.Fireblast; |
| 210 | + gui.SetProjectileCursor(); |
| 211 | + if (Input.GetKey(KeyCode.LeftAlt)) |
| 212 | + spellSelector.smartCast = true; |
| 213 | + } |
| 214 | + else if (controlType == CONTROL_TYPE.Gamepad) |
| 215 | + { |
| 216 | + lockStatus.currentSpell = (int)SPELLS.Fireblast; |
146 | 217 | spellSelector.smartCast = true; |
| 218 | + } |
147 | 219 | } |
148 | 220 |
|
149 | 221 | void CastSpell3(){ |
150 | | - lockStatus.currentSpell = (int)SPELLS.Teleport; |
151 | | - gui.SetProjectileCursor(); |
152 | | - if (Input.GetKey(KeyCode.LeftAlt)) |
| 222 | + if (controlType == CONTROL_TYPE.Mouse) |
| 223 | + { |
| 224 | + lockStatus.currentSpell = (int)SPELLS.Teleport; |
| 225 | + gui.SetProjectileCursor(); |
| 226 | + if (Input.GetKey(KeyCode.LeftAlt)) |
| 227 | + spellSelector.smartCast = true; |
| 228 | + } |
| 229 | + else if (controlType == CONTROL_TYPE.Gamepad) |
| 230 | + { |
| 231 | + lockStatus.currentSpell = (int)SPELLS.Teleport; |
153 | 232 | spellSelector.smartCast = true; |
| 233 | + } |
154 | 234 | } |
155 | 235 |
|
156 | 236 | void CastSpell4(){ |
157 | | - lockStatus.currentSpell = (int)SPELLS.Windblast; |
158 | | - gui.SetProjectileCursor(); |
159 | | - if (Input.GetKey(KeyCode.LeftAlt)) |
| 237 | + if (controlType == CONTROL_TYPE.Mouse) |
| 238 | + { |
| 239 | + lockStatus.currentSpell = (int)SPELLS.Windblast; |
| 240 | + gui.SetProjectileCursor(); |
| 241 | + if (Input.GetKey(KeyCode.LeftAlt)) |
| 242 | + spellSelector.smartCast = true; |
| 243 | + } |
| 244 | + else if (controlType == CONTROL_TYPE.Gamepad) |
| 245 | + { |
| 246 | + lockStatus.currentSpell = (int)SPELLS.Windblast; |
160 | 247 | spellSelector.smartCast = true; |
| 248 | + } |
161 | 249 | } |
162 | 250 |
|
163 | 251 | void CastSpell5(){ |
|
0 commit comments