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 PlayerMove : MonoBehaviour
- {
- [SerializeField] private LayerMask platformslayerMask;
- private Rigidbody2D rb2d;
- private BoxCollider2D bC2d;
- // Start is called before the first frame update
- void Start()
- {
- rb2d = transform.GetComponent<Rigidbody2D>();
- bC2d = transform.GetComponent<BoxCollider2D>();
- }
- // Update is called once per frame
- void Update()
- {
- Movement();
- if (isGrounded() && Input.GetKeyDown(KeyCode.Space))
- {
- float jumpVelocity = 10f;
- rb2d.velocity = Vector2.up * jumpVelocity;
- }
- }
- private bool IsGrounded()
- {
- RaycastHit2D raycastHit2d = Physiscs.BoxCast(bC2d.bounds.center, bC2d.bounds.size, 0f, Vector2.down * .1f, platformslayerMask);
- Debug.Log(raycastHit2d.collider);
- return raycastHit2d.collider != null;
- }
- private void Movement()
- {
- timeFrame = Time.deltaTime;
- moveXY.x = Input.GetAxis("Horizontal");
- speedXY.x = 5f;
- moveXY.y = Input.GetAxis("Vertical");
- speedXY.y = 5f;
- transform.Translate(moveXY.x * speedXY.x * timeFrame, moveXY.y * speedXY.y * timeFrame, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement