thieumao

Di Chuyen 2D Unity

Jul 7th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerScript : MonoBehaviour
  5. {
  6.     ///
  7.     /// 1 - The speed of the ship
  8.     ///
  9.     public Vector2 speed = new Vector2(50, 50);
  10.     // 2 - Store the movement
  11.     private Vector2 movement;
  12.     void Update()
  13.     {
  14.         // 3 - Retrieve axis information
  15.         float inputX = Input.GetAxis("Horizontal");
  16.         float inputY = Input.GetAxis("Vertical");
  17.         // 4 - Movement per direction
  18.         movement = new Vector2(
  19.             speed.x * inputX,
  20.             speed.y * inputY);
  21.     }
  22.     void FixedUpdate()
  23.     {
  24.         // 5 - Move the game object
  25.         rigidbody2D.velocity = movement;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment