- Home /
help with scripting combo
Hello all,
I am seeking help with developing a combo system. I have buttons in the game for the directions up, down, left, right, up left, up right, down left, and down right. I have boxes in the game which are obstacles, and there would be a combination on the boxes in order to break or destroy them so that the character can continue to move. so an example would be something like this: Three boxes in the game. The first box has a generated combo of 3 moves, which would be pressing the buttons [down, right, left]. The second box would have a combo of 2 moves [up, down]. The third box would have a combo of 5 moves [down, up left, down, right, left].
what I would like is that when the buttons are touched the combo would begin to have the boxes destroyed, but the boxes would not be destroyed unless the combo has been completed, and that every time a correct input is entered in the combo code for the box, a dust vxf prefab would be spawned. An example for box 2 would be: Player presses "up" button, the combo begins, and dust prefab is instantiated. Player presses down button, combo is complete and box is destroyed.
I would also like for the combo to only begin once the first character has been entered correctly, and that it would follow the particular sequence until completion.
Complex script. $$anonymous$$aybe someone is creating it for you right now, it's just difficult to make a script that allow you to do that within 7 hours.
Answer by Kamil1064 · Nov 05, 2016 at 10:32 AM
@mealone, check this out http://answers.unity3d.com/questions/1156608/random-keys-combo.html#comment-1157728
Answer by Rekrahttam1 · Jan 30, 2017 at 07:35 AM
I know this is a bit old, but to give you a direct answer:
Place this code on each box and set the dust and destruction prefabs. The KeyCode array sequence contains the list of required key presses.
public Transform dustEffect;
public Transform destroyEffect;
KeyCode[] sequence = new KeyCode[3] {KeyCode.DownArrow, KeyCode.RightArrow, KeyCode.LeftArrow};
int current = 0;
void Update() {
if (Input.GetKeyDown(sequence[current])) {
Instantiate(dustEffect, transform.position, transform.rotation);
current++;
if (current == sequence.Length) {
Instantiate(destroyEffect, transform.position, transform.rotation);
Destroy(gameObject);
}
} else {
current = 0; //causes sequence to restart if wrong key is pressed.
}
}
This will destroy all boxes that have the sequence, so if you only want one box active at a time, add:
bool isActive = false;
void Activate() {
isActive = true;
}
and modify the first if statement to:
if (Input.GetKeyDown(sequence[current]) && isActive) {
Then just call .Activate() on each box when you want it to become active.
A simple function to randomly generate a key sequence is easy to write, or one to set from a master function.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mirror : How to Sync child objects active status on join? 0 Answers
Make event stop 3 Answers
How would I make a ListChangedEvent? 1 Answer