- Home /
Vertical mobile input
Hi,
I need help with mobile input. I am making a simple pong game to put on the ios/android app store, and I have mostly everything down with pc controls, however, I know want to put in mobile controls. However, I can't just figure it out!
Essentially, I want the paddle to be where the players' finger is on the Y axis(It is gonna be locked on the X axis)
Thanks, and here is the script for the paddle player.
using UnityEngine;
using System.Collections;
public class Paddle : MonoBehaviour
{
public float paddleSpeed = 1;
public Vector3 playerPos;
public Vector3 player2Pos;
public bool player1;
void Update()
{
if (player1) {
//player one
float yPos = transform.position.y + (Input.GetAxis ("Vertical") * paddleSpeed);
playerPos = new Vector3 (-20, Mathf.Clamp (yPos, -13, 13), 0);
transform.position = playerPos;
} else{
//Player Two
float yPos2 = transform.position.y + (Input.GetAxis ("Vertical2") * paddleSpeed);
player2Pos = new Vector3 (20, Mathf.Clamp (yPos2, -13, 13), 0);
transform.position = player2Pos;
}
}
}
and here is the input for vertical and vertical2:
Comment