Skip to content

Instantly share code, notes, and snippets.

@kleberandrade
Created August 25, 2019 18:04
Show Gist options
  • Save kleberandrade/44da8470fb271913299835265144858f to your computer and use it in GitHub Desktop.
Save kleberandrade/44da8470fb271913299835265144858f to your computer and use it in GitHub Desktop.
using UnityEngine;
public class BreakoutPaddle : MonoBehaviour
{
// Velocidade do movimento
public float m_Speed = 20.0f;
private Rigidbody m_Body;
private void Start()
{
m_Body = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
// Recebe o entrada das setas direita e esquerda
float horizontal = Input.GetAxis("Horizontal");
// Cria um vetor aplicando a entrada no eixo X
Vector3 movement = Vector3.zero;
movement.x = horizontal * m_Speed * Time.deltaTime;
// Move o corpo rigído com o vetor de entrada
m_Body.MovePosition(m_Body.transform.position + movement);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment