Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- #region PlayerStats
- // Velocidade do player
- public float speed = 2.5f;
- #endregion
- #region UnityEvents
- void Start () {
- }
- void Update () {
- Moviment();
- }
- #endregion
- #region Methods
- /// <summary>
- /// Movimentação do Player
- /// </summary>
- void Moviment()
- {
- // Valores do eixo virtual (Sempre entre -1 e 1)
- float horizontal = Input.GetAxisRaw("Horizontal"); // Botões horizontais "A"e "D"
- float vertical = Input.GetAxisRaw("Vertical"); // Botões verticais "W" e "S"
- // deltaTime = O tempo em segundos que demorou para completar o último frame
- // Translate = Move o transform na direção e distancia desejada.
- if (horizontal != 0)
- {
- float x;
- x = horizontal * Time.deltaTime * speed;
- transform.Translate(x, 0, 0);
- }
- if (vertical != 0)
- {
- float y;
- y = vertical * Time.deltaTime * speed;
- transform.Translate(0, y, 0);
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement