-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PingGames
committed
Feb 22, 2023
1 parent
f9d4a7d
commit 074bfc9
Showing
4 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class PlayerController : MonoBehaviour | ||
{ | ||
private float _horizontal; | ||
private float _speed = 8f; | ||
private float _jumpingPower = 16f; | ||
|
||
[SerializeField] private Rigidbody2D _rb; | ||
[SerializeField] private Transform _groundCheck; | ||
[SerializeField] private LayerMask _groundLayer; | ||
|
||
void Update() | ||
{ | ||
_horizontal = Input.GetAxisRaw("Horizontal"); | ||
|
||
if (Input.GetButtonDown("Jump") && IsGrounded()) | ||
{ | ||
_rb.velocity = new Vector2(_rb.velocity.x, _jumpingPower); | ||
} | ||
|
||
if (Input.GetButtonDown("Jump") && _rb.velocity.y > 0f) | ||
{ | ||
_rb.velocity = new Vector2(_rb.velocity.x, _rb.velocity.y * 0.5f); | ||
} | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
_rb.velocity = new Vector2(_horizontal * _speed, _rb.velocity.y); | ||
} | ||
|
||
private bool IsGrounded() | ||
{ | ||
return Physics2D.OverlapCircle(_groundCheck.position, 0.2f, _groundLayer); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ TagManager: | |
- Default | ||
- TransparentFX | ||
- Ignore Raycast | ||
- | ||
- Ground | ||
- Water | ||
- UI | ||
- | ||
|