Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CubeControl : MonoBehaviour
  6. {
  7. public float speed = 10f;
  8. Rigidbody rb;
  9.  
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. rb = GetComponent<Rigidbody>();
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. float horizontal = Input.GetAxis ("Horizontal");
  20. float vertical = Input.GetAxis("Vertical");
  21.  
  22. Vector3 movement = new Vector3(horizontal * speed * Time.deltaTime, 0, vertical * speed * Time.deltaTime);
  23.  
  24. rb.MovePosition(transform.position + movement);
  25.  
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement