Advertisement
Guest User

Untitled

a guest
Feb 24th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MoveScript : MonoBehaviour
  5. {
  6.   // 1 - Designer variables
  7.  
  8.   /// <summary>
  9.   /// Object speed
  10.   /// </summary>
  11.   public Vector2 speed = new Vector2(10, 10);
  12.  
  13.   /// <summary>
  14.   /// Moving direction
  15.   /// </summary>
  16.   public Vector2 direction = new Vector2(-1, 0);
  17.  
  18.   private Vector2 movement;
  19.  
  20.   void Update()
  21.   {
  22.     // 2 - Movement
  23.     movement = new Vector2(
  24.       speed.x * direction.x,
  25.       speed.y * direction.y);
  26.   }
  27.  
  28.   void FixedUpdate()
  29.   {
  30.     // Apply movement to the rigidbody
  31.     rigidbody2D.velocity = movement;
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement