Hi, I’m trying to create a script in C# to move te player’s character, but it just doesn’t work.
This is it:
The last one gives me problems, it doesn’t work. The horizontal and vertical axes are setted in the Input Manager:
What’s wrong then??
Hi, I’m trying to create a script in C# to move te player’s character, but it just doesn’t work.
This is it:
The last one gives me problems, it doesn’t work. The horizontal and vertical axes are setted in the Input Manager:
What’s wrong then??
OK, first (rule #1), don’t paste a picture of your code… paste your code into code tags.
Second, I’m not at all clear on what you are trying to do here. First you check for specific keys and move your transform; that’s fine. Then you check for a Jump button, and translate up; that’s fine too (for starters, anyway). Then, if the mouse is down, you check some input axes… and do absolutely nothing with it.
You say it “doesn’t work,” but I don’t see how that can be. You haven’t told it to do anything, so not doing anything is working, isn’t it?
So, rule #2: any time you feel tempted to type “doesn’t work,” stop yourself. Instead type a description of (1) what happens, (2) what you expected to happen, and (3) how what happened is different from what you expected.
Ok, I’m sorry for the mistakes.
I want the player moves to the left, right up and down as you move the mouse, but only while right clicked. With that script it doesn’t. How can I do it? What am I doing wrong?
No worries, everybody’s new at first!
OK… so I would flip the logic around. Always write your methods to be “lazy,” that is, if you can think of an easy and reliable way to bail out early, do it! In this case, it sounds like you don’t want to do anything when mouse button 1 is not down. So the first line of Update should be:
if (!Input.GetMouseButton(1)) return; // bail out!
Then you can proceed with the rest of your code, safe in the assumption that if you get that far, you know the appropriate button is down.