Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Created February 12, 2023 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unity3dcollege/0c643cd1717157321b76f471bce107d2 to your computer and use it in GitHub Desktop.
Save unity3dcollege/0c643cd1717157321b76f471bce107d2 to your computer and use it in GitHub Desktop.
Player with Basic Jump
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>();
var vertical = rb.velocity.y;
if (Input.GetButtonDown("Fire1"))
vertical = 5;
rb.velocity = new Vector2(horizontal, vertical);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment