Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using SpriteTile;
- public class playerMovement : MonoBehaviour {
- public float Speed;
- public float jumpheight;
- Rigidbody2D body;
- public bool ground;
- private int Background;
- public TextAsset Level;
- public bool oground;
- public bool jumping;
- void Start () {
- body = GetComponent<Rigidbody2D>();
- Background = 1 << 8;
- }
- void Update () {
- if (Input.GetAxis("Horizontal") > 0)
- {
- body.AddForce(new Vector2(Speed, 0f));
- }
- if (Input.GetAxis("Horizontal") <0)
- {
- body.AddForce(new Vector2(-Speed, 0f));
- }
- //Jumping
- if ((Input.GetKeyDown(KeyCode.Space)) && (ground == true)) { ground = false; jumping = true; body.AddForce(new Vector2(0, jumpheight), ForceMode2D.Impulse); } else if (Input.GetKeyUp(KeyCode.Space)){ jumping = false; }
- //Giving Weight
- if ((Input.GetAxis("Vertical") < 0) && (ground == false) && (jumping == true)) { body.AddForce(new Vector2(0, -jumpheight), ForceMode2D.Impulse); }
- Vector3 down = transform.TransformDirection(Vector3.down);
- }
- void OnCollisionEnter2D(Collision2D stevenc)
- {
- Transform othersteve = stevenc.gameObject.transform;
- if ((othersteve.position.y < transform.position.y) && !(othersteve.position.y >= transform.position.y))
- {
- if (ground == false) { ground = true; }
- Debug.Log("Ground is now " + ground);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement