Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Done/Done_Scripts/Done_GameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void Update ()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
if ( (Input.GetKeyDown (KeyCode.R)) || (Input.touchCount > 0) )
{
Application.LoadLevel (Application.loadedLevel);
}
Expand Down
51 changes: 42 additions & 9 deletions Assets/Done/Done_Scripts/Done_PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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

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?

if(Input.touchCount > 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how do we play in the editor now? Can we?
We should establish different control methods for computer/editor and device

{
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;

Choose a reason for hiding this comment

The 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)
);
(

Choose a reason for hiding this comment

The 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);
}
Expand Down