Advertisement
crystalguy123

Untitled

Jan 30th, 2020
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMove : MonoBehaviour
  6. {
  7. [SerializeField] private LayerMask platformslayerMask;
  8. private Rigidbody2D rb2d;
  9. private BoxCollider2D bC2d;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. rb2d = transform.GetComponent<Rigidbody2D>();
  14. bC2d = transform.GetComponent<BoxCollider2D>();
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. Movement();
  21. if (isGrounded() && Input.GetKeyDown(KeyCode.Space))
  22. {
  23. float jumpVelocity = 10f;
  24.  
  25. rb2d.velocity = Vector2.up * jumpVelocity;
  26. }
  27. }
  28.  
  29. private bool IsGrounded()
  30. {
  31. RaycastHit2D raycastHit2d = Physiscs.BoxCast(bC2d.bounds.center, bC2d.bounds.size, 0f, Vector2.down * .1f, platformslayerMask);
  32. Debug.Log(raycastHit2d.collider);
  33. return raycastHit2d.collider != null;
  34.  
  35. }
  36. private void Movement()
  37. {
  38. timeFrame = Time.deltaTime;
  39. moveXY.x = Input.GetAxis("Horizontal");
  40. speedXY.x = 5f;
  41. moveXY.y = Input.GetAxis("Vertical");
  42. speedXY.y = 5f;
  43. transform.Translate(moveXY.x * speedXY.x * timeFrame, moveXY.y * speedXY.y * timeFrame, 0);
  44. }
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement