Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is a layer that you set up for ground, layers are next to tags on the inspector and you will often need to add one
- //The advantage to this is that you can change the layer of several objects to ground and not have to worry about tags or string checks
- //To see if your player is on the ground
- public LayerMask groundLayer;
- //This is the trigger2d collider you add under your players feet so you can easily debug where the box that is supposed to be doing
- //ground checks are. While you can declare the size of a box in the physics check I find it easier for new people to be able to see
- //the scale
- public BoxCollider2D thisGroundCol;
- //A simple float we trip back and forth so that the behavior can know if our player is touching the ground, any ground.
- public float isGrounded;
- public void Update()
- {
- isGrounded = Physics2D.IsTouchingLayers(thisGroundCol, groundLayer)
- if (Input.GetKeyDown("up") && isGrounded)
- {
- rigidbody2d.velocity = Vector2.up * jumpheight;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement