-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Touch Controls #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,11 @@ public class Done_PlayerController : MonoBehaviour | |
public float speed; | ||
public float tilt; | ||
public Done_Boundary boundary; | ||
|
||
public GameObject shot; | ||
public Transform shotSpawn; | ||
public float fireRate; | ||
|
||
private float nextFire; | ||
|
||
void Update () | ||
|
@@ -28,21 +28,54 @@ void Update () | |
audio.Play (); | ||
} | ||
} | ||
|
||
void FixedUpdate () | ||
{ | ||
float moveHorizontal = Input.GetAxis ("Horizontal"); | ||
float moveVertical = Input.GetAxis ("Vertical"); | ||
|
||
|
||
|
||
//check for touches.. move ship towards first touch if present | ||
if(Input.touchCount > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So how do we play in the editor now? Can we? |
||
{ | ||
Touch touch = Input.GetTouch(0); | ||
|
||
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) | ||
{ | ||
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 0 )); | ||
|
||
if( touchPosition.x > transform.position.x ) | ||
{ | ||
moveHorizontal = 1f; | ||
} | ||
else | ||
{ | ||
moveHorizontal = -1f; | ||
} | ||
|
||
if( touchPosition.z > transform.position.z ) | ||
{ | ||
moveVertical = 1f; | ||
} | ||
else | ||
{ | ||
moveVertical = -1f; | ||
} | ||
|
||
} | ||
//return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get rid of this? |
||
} | ||
|
||
|
||
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); | ||
rigidbody.velocity = movement * speed; | ||
|
||
rigidbody.position = new Vector3 | ||
( | ||
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), | ||
0.0f, | ||
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax) | ||
); | ||
( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of empty tab spaces |
||
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), | ||
0.0f, | ||
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax) | ||
); | ||
|
||
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would make sense to make a new function to handle all user input?