MyCharacterController.cs 631 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MyCharacterController : MonoBehaviour
  5. {
  6. //½ÇÉ«¿ØÖÆÆ÷
  7. private CharacterController cc;
  8. //ËÙ¶È
  9. public float speed = 10;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. cc = GetComponent<CharacterController>();
  14. }
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. float x = Input.GetAxis("Horizontal");
  19. float y = Input.GetAxis("Vertical");
  20. if (x != 0 || y != 0)
  21. {
  22. cc.SimpleMove(new Vector3(x, 0, y) * speed);
  23. }
  24. }
  25. }