SimplePlayerController.cs 595 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SimplePlayerController : MonoBehaviour
  5. {
  6. bool canUp, canDown, canLeft, canRight = false;
  7. Rigidbody rb;
  8. float speed = 10;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. rb = GetComponent<Rigidbody>();
  13. }
  14. void Move(float x, float z){
  15. rb.velocity = new Vector3(x*speed, x*speed/2, z*speed);
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. Move(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"));
  21. }
  22. }