hello,
I have a player controller working perfectly using W, S and Space keys to move up, down and shoot but I want to convert these into mobile touch controls. I have added some buttons to my canvas but I don’t know how to convert to touch controls. I know I probably need a separate script and set the buttons up with on click functions on that script but I don’t know how to go about the script.
Here is my current player controller script:
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float maxSpeed = 5f;
public float shipBoundryradious = 0.5f;
public GameManager theGameManager;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 pos = transform.position;
pos.y += Input.GetAxis("Vertical") * maxSpeed * Time.deltaTime;
if (pos.y + shipBoundryradious > Camera.main.orthographicSize)
{
pos.y = Camera.main.orthographicSize - shipBoundryradious;
}
if (pos.y - shipBoundryradious < -Camera.main.orthographicSize)
{
pos.y = -Camera.main.orthographicSize + shipBoundryradious;
}
transform.position = pos;
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "killbox")
{
theGameManager.RestartGame();
}
}
}
thanks,
