#unity #tutorial #input #keyboard #script
!!! these characters "˂" and "˃" are unicodes, you have to replace it with ascii-codes !!!
// -- C# Script --
using UnityEngine;
public class MoveSphere : MonoBehaviour {
public float speed = 1f;
Rigidbody rb;
void Start()
{
// Get reference to own Rigidbody-component.
rb = GetComponent˂Rigidbody˃();
}
// Update is called once per frame
void Update()
{
// values between -1 and +1
float moveVertical = Input.GetAxis("Vertical"); // keyboard forward backward
float moveHorizontal = Input.GetAxis("Horizontal"); // keyboard left right
// Y = 0f because we do not move up and down
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical); // Create a Vector3
rb.AddForce(movement * speed);
}
}