Beg_Productions

Script de Player Prefab (Infinite Jumper)

Aug 22nd, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class J_PlayerController_Jumping : MonoBehaviour {
  5.  
  6.     [SerializeField]
  7.     float moveSpd;
  8.  
  9.     [SerializeField]
  10.     float jumpPower;
  11.  
  12.     Rigidbody2D myRigidbody2d;
  13.     SpriteRenderer mySpriteRenderer;
  14.  
  15.     void Awake(){
  16.  
  17.         myRigidbody2d = GetComponent<Rigidbody2D> ();
  18.         mySpriteRenderer = GetComponent<SpriteRenderer> ();
  19.  
  20.    
  21.     }
  22.  
  23.     void Update(){
  24.  
  25.         FlipCharacter ();
  26.  
  27.  
  28.  
  29.     }
  30.  
  31.  
  32.     void FixUpdate () {
  33.  
  34.         Movement ();
  35.  
  36.    
  37.     }
  38.  
  39.     void OnCollisionEnter2D(Collision2D col) {
  40.        
  41.         myRigidbody2d.velocity = new Vector2 (myRigidbody2d.velocity.x, 0f);
  42.         myRigidbody2d.AddForce (Vector2.up * jumpPower);
  43.  
  44.     }
  45.  
  46.     void Movement(){
  47.  
  48.         myRigidbody2d.AddForce (Vector2.right * Input.GetAxis ("Horizontal") * moveSpd);
  49.  
  50.     }
  51.  
  52.     void FlipCharacter(){
  53.  
  54.         if (Input.GetAxisRaw ("Horizontal") < 0)
  55.             mySpriteRenderer.flipX = true;
  56.         else if (Input.GetAxisRaw ("Horizontal") > 0)
  57.             mySpriteRenderer.flipX = false;
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment