Advertisement
Guest User

Untitled

a guest
Dec 5th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour
  5. {
  6.  
  7.     public float moveSpeed = 5;
  8.     public float jumpHeight = 100;
  9.     public Rigidbody2D rigidBody;
  10.  
  11.     // Use this for initialization
  12.     void Start()
  13.     {
  14.         rigidBody = GetComponent<Rigidbody2D>();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
  21.         {
  22.             transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
  23.         }
  24.  
  25.         if (Input.GetKeyDown(KeyCode.W))
  26.         {
  27.             rigidBody.AddForce(new Vector2(0, jumpHeight));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement