Hello,
Was just wondering how hard it is to program a Rock Paper Scissors minigame with JavaScript in Unity. Can someone give me some pointers?
Hello,
Was just wondering how hard it is to program a Rock Paper Scissors minigame with JavaScript in Unity. Can someone give me some pointers?
If you already know how to program, it should be easy. If you’re a beginner to programming, it might take some work.
What experience do you have? Are you already comfortable with UnityScript? Which parts do you need help with?
I’m a beginner when it comes to JavaScript, although I’ve used other programming languages before and I did some minor JavaScript things.
There’s no specific parts I need help with yet, I haven’t started yet. I was just wondering if this is reachable or not within a reasonable time.
Sure - that would definitely be at the simple/obtainable end of the scale.
Hello, sorry to bump this up again, but I want to start making this as quickly as possible now and I need some advice.
To start with, this battle (or minigame) should be initiated when the player meets an enemy. So in order to use this system effectively I need to be able to call it up quickly. The battle is won when player or enemy beats the other one at least two out of three times.
I have an idea in my head, and based on how Unity works, I think this system could be handled in two different objects: A counter to keep the score, and and the actual slots representing the rock, paper, and scissors.
The “slots” object would basically consist of two slots, one for the player and one for the enemy. The slots depict the images of a rock, paper, and scissors, one at a time, and the player can navigate through them with the up and down keys. The enemy does this too, and then both pick one of the three. You know the works, rock beats scissors, scissors beats paper, and paper beats rock.
So then for the counter object, this would basically be two images as well, for player and enemy. Both would consist of three empty squares, and after each “strike”, one of the squares is marked with a green check or red cross depending if you won or lost. If you win at least two out of three, you win. Otherwise, you lose.
Anyway, if it’s still not completely clear check out this YouTube movie:
The only difference is that in that video the slots change automatically while in my system the player can select one manually and make the choice themselves.
Okay, now for the part I need help with… I have limited experience in Unity. I’ve got the worldbuilding and interface down, and I’ve done some small things in JavaScript, but this is considerably more challenging. I plan to do most of the work myself, however I just don’t know where to start.
So, my question is, does anyone have good advice, any tips I can use, tutorials I should check out? All help is welcome, because frankly, I need it.
It’s not clear from your post which part you need help with, so I’d suggest picking one aspect of the problem, focusing on that, and asking about it if you need help. For example, do you know how to detect and handle user input? Can you write code to print a message to the console indicating when the up or down arrow key has been pressed? If not, I’d start there (check out the docs for the Input class for details). If that part’s easy though and the problem is actually elsewhere, perhaps you could be more specific about where you need help.
I would suggest, upon activation of the minigame, spawn three icon objects with pictures for rock, paper and scissors. Set up a variable for the player’s answer and have paper = 1, scissors = 2, rock = 3.
Have the AI generate a random number (or you can be fancy with this and put some logic behind the number) or 1, 2 or 3.
Then subtract the player’s number from the AI’s number. If you get a 1 (2-1 or 3-2) or a -2 (1-3) then the player wins. If you get a -1 or a 2 then the AI wins. If you get a 0 (played the same number) then it’s a tie.
Have another variable for the total score (that starts at 0). Every time the player wins, add 1 to the score, every time the AI wins subtract 1. If the score reaches 2 then the player wins, if it reaches -2 then the player loses.
Hope that helped with the logic.
EDIT:
Although this seems unlikely, it would be thoughtful to add a mechanism that will force a winning point on the player (play the losing sign depending on what the player chose) if there are too many ties in a row.
It is technically possible for the player to continue tying with the computer if they both pick the same number.
I had something like this in mind as well, but now I have a more clear image in my head.
To Jesse, the problem is there aren’t specific parts I need help with yet because I haven’t started to script yet. I don’t know what to do first, how to start. But I’ll follow your advice and check out those documents.
Anyone know where I can get more information on the Input class?
I’ve checked here Unity - Scripting API: Input
But all it really tells me is what the Input class does, I still don’t know how to use it in a script.
It’s all there; just click on the name of a property or function and you’ll be taken to the documentation for that property or function, which, in general, will include code examples in each of the supported languages.
If you need more info on a particular feature, try searching the forums for the feature in question; input is discussed fairly frequently, so there’s plenty of example code to be found in the forum archives.
If after that you have specific questions about anything, post back.