move unity cube code example
Example: How to make a cube move in unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
Rigidbody rb;
Vector3 Vec;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * 500f);
}
Vec = transform.localPosition;
Vec.y += Input.GetAxis("Jump") * Time.deltaTime * 20;
Vec.x += Input.GetAxis("Horizontal") * Time.deltaTime * 20;
Vec.z += Input.GetAxis("Vertical") * Time.deltaTime * 20;
transform.localPosition = Vec;
}
}