Advertisement
Guest User

PlayerMovement.cs

a guest
Aug 31st, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerMovement : MonoBehaviour
  5. {
  6.     public float speed;
  7.     private Rigidbody2D rigidbody;
  8.  
  9.     void Start()
  10.     {
  11.         rigidbody = GetComponent<Rigidbody2D>();
  12.     }
  13.  
  14.     void Update()
  15.     {
  16.         Movement();        
  17.     }
  18.  
  19.     void Movement()
  20.     {
  21.         if (Input.GetKey(KeyCode.A))
  22.         {
  23.             transform.Translate(-speed * Time.deltaTime, 0, 0);
  24.         }
  25.         else if (Input.GetKey(KeyCode.D))
  26.         {
  27.             transform.Translate(speed * Time.deltaTime, 0, 0);
  28.         }
  29.     }
  30.  
  31.     void OnCollisionEnter2D(Collision2D other)
  32.     {
  33.         if (other.gameObject.tag == "Platform")
  34.         {
  35.             rigidbody.AddForce(new Vector2(0f, 500f));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement