Advertisement
Eriknem

movement

Nov 20th, 2016
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Movement : MonoBehaviour {
  5.  
  6.     public float jumpHeight = 5.0f;
  7.     public float moveSpeed = 2.0f;
  8.  
  9.  
  10.     Rigidbody2D playerRigidbody;
  11.  
  12.  
  13.  
  14.     public bool LeftPressed = false;
  15.     public bool RightPressed = false;
  16.  
  17.     // Use this for initialization
  18.     void Start () {
  19.         playerRigidbody = GetComponent<Rigidbody2D>();
  20.  
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void FixedUpdate () {
  25.        
  26.         if (LeftPressed == true){
  27.             Left ();
  28.         }
  29.  
  30.         if (RightPressed == true){
  31.             Right ();
  32.         }
  33.  
  34.     }
  35.  
  36.     public void Jump ()
  37.     {
  38.        
  39.         playerRigidbody.AddForce(Vector2.up * jumpHeight, ForceMode2D.Impulse);
  40.            
  41.     }
  42.  
  43.  
  44.  
  45.     void Left ()
  46.     {
  47.  
  48.         transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
  49.  
  50.     }
  51.  
  52.     public void onPointerDownLeftButton()
  53.     {
  54.         LeftPressed = true;
  55.     }
  56.     public void onPointerUpLeftButton()
  57.     {
  58.         LeftPressed = false;
  59.     }
  60.  
  61.  
  62.     public void Right ()
  63.     {
  64.  
  65.         transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
  66.  
  67.     }
  68.  
  69.     public void onPointerDownRightButton()
  70.     {
  71.         RightPressed = true;
  72.     }
  73.  
  74.     public void onPointerUpRightButton()
  75.     {
  76.         RightPressed = false;
  77.     }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement