Hi all,
I have been reading and searching many days now and i am still having hard time to find solution to my problem.
I got a code (from forums) that made my character move left and right when I touch the side of the screen, and it is on the stationary phase of my touch code. My problem is on my first touch phase which is began and it should just start the game and make my rocket fly upward it also (the touchphase.began) moves the rocket from the side of my finger where it touches. I am hoping to resolve this with the help here guys. Here are the codes that i got
This is on the void update part;
if (Input.touchCount >= 1)
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
{
// starting touch.
stateMachine.ProcessTriggerEvent ("TAP");
Vector3 newVelocity = GetComponent<Rigidbody> ().velocity;
newVelocity.y = moveSpeed;
GetComponent<Rigidbody> ().velocity = newVelocity;
}
//and this is the code i got for the stationary phase
if(Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Stationary)
{
Vector2 touchPosition = Input.GetTouch(0).position;
double halfScreen = Screen.width / 2.0;
//Check if it is left or right?
if(touchPosition.x < halfScreen){
player.transform.Translate(Vector3.left * 5 * Time.deltaTime);
} else if (touchPosition.x > halfScreen) {
player.transform.Translate(Vector3.right * 5 * Time.deltaTime);
}
}
What should i do so that my first tap on the screen will just make the object (rocket) fly and does not move from either side.
Thanks a lot