- Home /
Move while mouse button is held down
Hello folks, I'd start by saying I'm new to coding and unity. I've been working on a little personal project mainly working from different tutorials trying to modify things to my liking which has been going pretty well up until the current issue.
I'm trying to set up movement for my player (currently a cube), I would like to set it up so it would move towards the mouse cursor when the button was held down then stop when the mouse button is released. Ideally grid based as well.
Any help is appreciated, I feel defeated by asking for help but its been researching this for 3 days now and progress is a stand still.
Thanks.
Answer by Larkman · Apr 25, 2017 at 05:14 AM
GetAxis method will return float number between -1 and 1 while the requested input is being used.
void Update () {
if (Input.GetAxis("Fire1") > 0f) {
// Movement();
}
}
You can find the InputManager on Edit > Project Setting > Input.
Answer by ben-rasooli · Mar 11, 2018 at 03:32 AM
Unity already has a method for mouse which is Input.GetMouseButton(0)
Your answer
Follow this Question
Related Questions
How to properly set the position clicked by the mouse? 0 Answers
Mouse-click movement 0 Answers
Help with turn based Movement in a grid 2 Answers
Object Movement via Mouse Click? 3 Answers
Click Goes Everywhere 0 Answers