using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleMovement : MonoBehaviour
{
//Cancellare start
//dichiaro le variabili
public float movementSpeed = 5f;
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(Vector3.forward * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(-Vector3.forward * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(-Vector3.right * movementSpeed * Time.deltaTime);
}
}
}
I dunno, does it work?
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed; //your speed value here.
public float sidewaysSpeed; //your sideways Speed value here.
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal"); //GetAxis("[horizontal/vertical here]") is like a slider for vertical and horizontal going from -1 to 1.
//thisway you dont have to get the different arrow keys and best of all, it also should work with wasd.
float verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * speed * verticalInput * Time.deltaTime);
transform.Translate(Vector3.right * sidewaysSpeed * horizontalInput * Time.deltaTime); //with this code, you only have to write transform.Translate two times and you can even adjust the speed for horizontal and vertical movement individually.
}
}
Let me know if something is unclear or you need assistance with anything else.
There are also a lot of tutorials on YouTube about all the different ways to make a PlayerController.