- Home /
Scroll rect with mouse locked
Hello all
I have a scroll rect, that works ok if my mouse is unlocked, and i move the mouse over the the scoll rect. Happy days
However if my mouse is locked, which it will be as i dont plan on using the mouse, i can no longer scroll through my scroll rec.
basically when i toggle my scroll rec on my ui i want to scroll with the up and down arrows.
Any ideas?
Answer by RobAnthem · Mar 12, 2019 at 03:49 PM
You'll need to modify your scroll class or create a class to handle the scrolling and use it to handle input received and pass the scroll amount/direction to your scroll view object. Something like
public ScrollRect scrollRect;
public float speed;
public KeyCode Up, Down;
void Update()
{
Vector2 velocity = Vector2.zero;
if (Input.GetKey(Up))
{
velocity = Vector2.up * speed;
}
else if (Input.GetKey(Down))
{
velocity = -Vector2.up * speed;
}
scrollRect.velocity = velocity;
}
Rob that works a treat.. thank you so much. Its not letting me accept as an answer. can you reply below, so i can accept it.
Thank you again
Glad I could help, converted to an answer you can now accept :)
Your answer
Follow this Question
Related Questions
2D, lock the "y" axis 1 Answer
PlayerPrefs Problem crashing with SetBool 2 Answers
Forcing a rotation point 2 Answers
Hide and lock the mouse cursor (beginner) 0 Answers
lock local x-translation on rigidbody with ice material 3 Answers