- Home /
onMouseDrag scroll
Hello all I want to scroll an object (in 3D space) only on the Y axis (up and down.
It's a Game object with a lot of pictures set as textures on planes. I want you to come across them in space and be able to Scroll the whole thing up & Down.

I dont want to have it as a GUI, so I was thinking of creating an onMouseDrag
#pragma strict
var cam : Camera;
var myScroll : GameObject;
var scrollDrag : boolean;
function OnMouseDown()
{
scrollDrag = true;
}
function OnMouseUp()
{
scrollDrag = false;
}
function OnMouseDrag()
{
if (scrollDrag == true)
{
screenPosition.y += Input.GetAxis("Mouse Y");
myScroll.transform.position = cam.ScreenToWorldPoint(screenPosition);
}
}
Although I'd like it to have momentum when you lift mouseUp I have cobbled this together but I need Help Please Thanks in advance ~be
Here is another pass if it helps inspire
(although it's a C# script)
using UnityEngine;
using System.Collections;
public class drag : $$anonymous$$onoBehaviour {
private Vector3 last$$anonymous$$ousePosition;
void On$$anonymous$$ouseDown() {
last$$anonymous$$ousePosition = Input.mousePosition;
}
void On$$anonymous$$ouseDrag() {
Vector3 distance = Input.mousePosition - last$$anonymous$$ousePosition;
Debug.Log("The mouse moved " + distance.magnitude + " pixels");
// $$anonymous$$ove to last $$anonymous$$ouse Pos
Input.mousePosition = transform.Translate.position;
}
}
But here, I gather I also have to convert world Space
ScreenToWorldPoint(screenPoint)
Thank you !
~be
Your answer
Follow this Question
Related Questions
How to read Shift + Click input? 1 Answer
Two Strange MathF Clamp Issues: The Disabling of OnMouseDrag 2 Answers
Shooting bullets OnMouseDrag, time delay issues 3 Answers
Starting drag onMouseEnter 0 Answers