Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active February 12, 2023 21:08
Show Gist options
  • Save unity3dcollege/ab2a41fab2950e09f140e38cc82d2ab0 to your computer and use it in GitHub Desktop.
Save unity3dcollege/ab2a41fab2950e09f140e38cc82d2ab0 to your computer and use it in GitHub Desktop.
Player with Horizontal Movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var horizontal = Input.GetAxis("Horizontal");
Debug.Log(horizontal);
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(horizontal, rb.velocity.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment