Last active
February 5, 2016 20:34
-
-
Save alasdairhurst/58a271ab52680b839c6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class MouseMoveTransform : MonoBehaviour { | |
Vector3 oldMousePos; | |
public float Speed = 1; | |
void Start() { | |
oldMousePos = Input.mousePosition; | |
} | |
// Update is called once per frame | |
void FixedUpdate () { | |
// get how much the mouse moved | |
Vector3 deltaMouse = Input.mousePosition - oldMousePos; | |
// move the attached object the direction that the mouse moved. You can speed it up or slow it down by modifiying speed | |
transform.Translate(deltaMouse * Speed); | |
// save the current mouseposition to use in the next loop | |
oldMousePos = Input.mousePosition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment