Advertisement
JuiceBoxx

ME PLAYER MOVEMENT

Mar 18th, 2015
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using SpriteTile;
  4.  
  5. public class playerMovement : MonoBehaviour {
  6.  
  7.     public float Speed;
  8.     public float jumpheight;
  9.     Rigidbody2D body;
  10.     public bool ground;
  11.     private int Background;
  12.     public TextAsset Level;
  13.     public bool oground;
  14.     public bool jumping;
  15.  
  16.     void Start () {
  17.  
  18.         body = GetComponent<Rigidbody2D>();
  19.         Background = 1 << 8;
  20.    
  21.     }
  22.    
  23.     void Update () {
  24.  
  25.  
  26.        
  27.  
  28.         if (Input.GetAxis("Horizontal") > 0)
  29.         {
  30.             body.AddForce(new Vector2(Speed, 0f));
  31.         }
  32.         if (Input.GetAxis("Horizontal") <0)
  33.         {
  34.             body.AddForce(new Vector2(-Speed, 0f));
  35.         }
  36.          
  37.         //Jumping
  38.  
  39.         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; }
  40.  
  41.         //Giving Weight
  42.         if ((Input.GetAxis("Vertical") < 0) && (ground == false) && (jumping == true)) { body.AddForce(new Vector2(0, -jumpheight), ForceMode2D.Impulse); }
  43.  
  44.         Vector3 down = transform.TransformDirection(Vector3.down);
  45.  
  46.        
  47.        
  48.  
  49.     }
  50.  
  51.     void OnCollisionEnter2D(Collision2D stevenc)
  52.     {
  53.  
  54.         Transform othersteve = stevenc.gameObject.transform;
  55.  
  56.  
  57.         if ((othersteve.position.y < transform.position.y) && !(othersteve.position.y >= transform.position.y))
  58.         {
  59.             if (ground == false) { ground = true; }
  60.             Debug.Log("Ground is now " + ground);
  61.            
  62.  
  63.         }
  64.  
  65.     }
  66.    
  67.    
  68.    
  69.      
  70.      
  71.  
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement