Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private var characterAnimator : Animator;
  2. var speed : float = 3;
  3. var grounded : boolean = false;
  4. var jumpHeight : int;
  5. var isKinematic : boolean = false;
  6.  
  7. function OnTriggerEnter2D(collienter : Collider2D) {
  8.         if(gameObject.tag == "Player")
  9.             {
  10.             grounded = true;
  11.             rigidbody2D.isKinematic = true;
  12.            
  13.             }
  14.         }
  15. function OnTriggerExit2D(collienter : Collider2D) {
  16.         if(gameObject.tag == "Player")
  17.             {
  18.             grounded = false;
  19.             rigidbody2D.isKinematic = false;
  20.            
  21.             }
  22.         }
  23.  
  24.        
  25. function Awake() {
  26.         characterAnimator = gameObject.GetComponent("Animator");
  27.     }
  28.  
  29. function Start () {
  30.     }
  31.  
  32. function Update () {
  33.     if (Input.GetKey(KeyCode.A)) {
  34.         gameObject.transform.position.x -= speed * Time.deltaTime;
  35.         gameObject.transform.rotation.y = 180;
  36.         characterAnimator.SetBool("walk", true);
  37.         }else if (Input.GetKey(KeyCode.D)) {
  38.                   gameObject.transform.position.x += speed * Time.deltaTime;
  39.                   gameObject.transform.rotation.y = 0;
  40.                   characterAnimator.SetBool("walk", true);
  41.                 }else {
  42.                        gameObject.transform.position.x += 0 * Time.deltaTime;
  43.                        characterAnimator.SetBool("walk", false);
  44.                        }
  45.     if (Input.GetKey(KeyCode.Space)) {
  46.         if(grounded) {
  47.             rigidbody2D.isKinematic = false;
  48.             jumpHeight = 3 * 250;
  49.             gameObject.rigidbody2D.AddForce(Vector2.up * jumpHeight);
  50.             grounded = false;
  51.  
  52.             }
  53.         }
  54.     }
  55.    
  56. /*function OnTriggerExit(colliexit : Collider) {
  57.         if(colliexit.gameObject.tag == "Player")
  58.             {
  59.             rigidbody2D.isKinematic = false;
  60.             }
  61.         }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement