I’m working on an old-school battle menu for an RPG, where the cursor “hops” between the different choices every time you press the up or down arrow keys. Most movement tutorials out there only cover constant movement as long as you hold the key down, but I need it to travel a set distance once per key press and then stop. Think how old final fantasy battle menus worked. If it helps, the cursor’s starting Y position is at -0.711836. The other two Y positions I need it to be in are -0.881836 and -1.041836.
Also, I can try to figure this out myself, but I’d also greatly appreciate some direction on how to get the cursor position to “loop” back to the top if you press down again at the bottom of the menu, or down to the bottom if you press up again at the top. I’m sorry for asking something that must seem terribly basic, but I’m a really bad learner if the info I’m given isn’t specific.
cursorObject.transform.position =
Where is a Vector3
Edit: It occurred to me that maybe you mean you want to move the hardware cursor to a specific place.
You can’t do that. You need to create a software cursor. You can either do it as an object in 3D or as a texture drawn with GUI.DrawTexture
Create an array of floats representing the various y positions that the cursor could be at. For example, array[0] = -0.711836f, array[1] = -0.881836, etc. You’ll need an int variable too. For example, int i = 0.
Now at that start, set the cursor’s y position to array*, which will in this case be -0.711836f. If the user presses the key to move the cursor, increment i by 1. Then, again set the cursors position to i. You can wrap it back around to the original position by adding a check to make sure i never exceeds the bounds of the array, like this:*
if (userInput) {
if (i == 0) {
//If it’s the top menu item, wraparound to bottom
i = array.count() - 1;
}
else if (i == array.count() - 1) {
//If it’s the last menu item, wraparound to top
i = 0;
}
else {
//Otherwise, go to next item
i++;
}
}
Then set it using something like:
cursorObject.transform.position = new Vector3(cursorObject.transform.position.x,
array*,*
cursorObject.transform.position.z);
You’ll have to tweak that code to get it to work for you but hopefully it gives you the basic idea of what to do!
Look at the key down function in input - it only fires when the key is first hit.
When the key is first hit, add a fixed value to the transform position - I.e. Transform.position+=new Vector3(1,0,0);
You can then test if the y position is greater than a certain amount, and if it is, wrap it back around to the start position.
That assumes there is a fixed distance between each position. If the positions are just arbitrary points in space then you’ll need to store them in an array, or get cleverer and place game objects at each point you want to go to so you can use them as reference points.
Hope that helps - apologies for lack of code - I’m on my iPad right now.