Entiende el código correctamente previamente a utilizarlo a tu trabajo y si ttienes algo que aportar puedes decirlo en los comentarios.
Ejemplo 1: personaje de movimiento de unidad
usingUnityEngine;publicclassPlayerMovement:MonoBehaviour[SerializeField]privatefloat speed =5.0f;privatevoidUpdate()var horizontal = Input.GetAxis("Horizontal");var vertical = Input.GetAxis("Vertical");
transform.Translate(newVector3(horizontal,0, vertical)*(speed * Time.deltaTime));
Ejemplo 2: mover la unidad del personaje
usingUnityEngine;usingSystem.Collections;// This script moves the character controller forward// and sideways based on the arrow keys.// It also jumps when pressing space.// Make sure to attach a character controller to the same game object.// It is recommended that you make only one call to Move or SimpleMove per frame.publicclassExampleClass:MonoBehaviourCharacterController characterController;publicfloat speed =6.0f;publicfloat jumpSpeed =8.0f;publicfloat gravity =20.0f;privateVector3 moveDirection = Vector3.zero;voidStart()
characterController =GetComponent<CharacterController>();voidUpdate()if(characterController.isGrounded)// We are grounded, so recalculate// move direction directly from axes
moveDirection =newVector3(Input.GetAxis("Horizontal"),0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;if(Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.deltaTime;// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
Sección de Reseñas y Valoraciones
Puedes asistir nuestra misión añadiendo un comentario o dejando una puntuación te lo agradecemos.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)