Advertisement
crystalguy123

Untitled

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