Skip to content

Instantly share code, notes, and snippets.

@alasdairhurst
Last active February 5, 2016 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alasdairhurst/58a271ab52680b839c6a to your computer and use it in GitHub Desktop.
Save alasdairhurst/58a271ab52680b839c6a to your computer and use it in GitHub Desktop.
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