Arrowkey controls to android touchscreen?

Updated on May 6, 2017 in [A] Tutorials
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
0 on May 6, 2017

I’ve followed along with the Make a Game turorial on youtube and I’m pretty much done with the game but I’d like to convert it to an android game instead of a web or standalone. I’ve gotten everything else to work except the movement of the ball (left and right). All help is appreciated as this is my first game ever.

Here is my BallControl code, the input touch things are stuff that i experimented with and those are commented out.

#pragma strict

var rotationSpeed = 100;
var jumpHeight = 8;

var Hit01 : AudioClip;
var Hit02 : AudioClip;
var Hit03 : AudioClip;

var distToGround : float;

function Start ()
{
// Getting the distance from the center to the ground.
distToGround = GetComponent.<Collider>().bounds.extents.y;
}

function Update ()
{
// handle ball rotation
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent.<Rigidbody>().AddRelativeTorque (Vector3.back * rotation);

// if (Input.touchCount > 1 && IsGrounded ())
if (Input.GetKeyDown (KeyCode.Space) && IsGrounded ())
// if(Input.GetTouch(0).phase == TouchPhase.Stationary || Input.GetTouch(0).phase == TouchPhase.Stationary)
{
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
}

}

//if(Input.GetTouch(0).phase == TouchPhase.Stationary || Input.GetTouch(0).phase == TouchPhase.Stationary)
//{
// // Apply forward force
// this.GetComponent.<Rigidbody>().AddForce(this.transform.forward * 2.5f);
//}

function IsGrounded () : System.Boolean //check if we are on the ground. Return true if we are, else null.
{
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}

function OnCollisionEnter ()
{
var theHit = Random.Range(0, 3);

if (theHit == 0)
{
GetComponent.<AudioSource>().clip = Hit01;
}
else if (theHit == 1)
{
GetComponent.<AudioSource>().clip = Hit02;
}
else
{
GetComponent.<AudioSource>().clip = Hit03;
}
GetComponent.<AudioSource>().pitch = Random.Range (0.9, 1.1);
GetComponent.<AudioSource>().Play();
}

  • Liked by
Reply