- Home /
Question by
rabahabaja0 · Sep 01, 2021 at 01:05 AM ·
3dscript.touchscreenleftright
Move player to left and right ( android Touche )
this script its for windows keyboard i want switch to android touche
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController: MonoBehaviour
{
public float horizontalInput ;
public float speed = 10.0f;
public GameObject character;
public GameObject projectilePrefab;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(transform.position.x < -20)
{
transform.position = new Vector3(-20, transform.position.y , transform .position.z );
}
else if (transform.position.x > 20)
{
transform.position = new Vector3(20.0f, transform.position.y, transform.position.z);
}
horizontalInput = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * horizontalInput * Time.deltaTime * speed);
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
}
}
}
Comment