Ok, I want to make a little script that detect what button I pressed then place the GUI element in spot1 and so on …
If you press UP,DOWN,LEFT,RIGHT then the in the GUI element 1(Up),GUI element 2(Down) and so on …
I have no idea where to start, could someone point me in the right direction ?
much like playing the ocarina in the zelda games
here is a little vid that shows the zelda ocarina thing:http://www.youtube.com/watch?v=eteScd3NLaM&feature=related circa 30 seconds in the video.
I don’t need all the advance scripting and GUI stuff.
Just a basic example of se what button is pressed then place the correct GUItexture in slot 1 and so on. ???
You could use an array for all the GUITextures, which would initially contain blank textures or nulls. Use an integer counter variable to mark how far along the sequence the player has progressed. Each frame, in a loop, draw all the textures up to the point the integer counter has reached. Every time the user adds another texture (with keystrokes or whatever) place it in the array element indexed by the counter and then increment the counter afterwards.
So the basic pseudocode is:-
function OnGUI() {
if (keystroke) {
texArray[counter] = next texture
counter++
}
for (int i = 0; i < counter; i++) {
draw texArray[i];
}
}
Ok, thanks.
But a other idea is to check if the combo is pressed then do animation and GUI animation.
Any ideas to check if the UP,UP,LEFT,RIGHT is pressed in a combo ? or something like that ? It doesn’t need a timer between the presses but when pressed wrong it have to start over again.
So the code would be
if(UP,UP,DOWN,LEFT)
{
play song 2
Do GUI animation
}
You could just store the values in an array as they are entered and then check the whole sequence each frame to see if it is correct.
Ok, I found this script on the wiki
class KeyCombo {
var buttons : String[];
var currentIndex : int=0; //moves along the array as buttons are pressed
var allowedTimeBetweenButtons : float = 0.3; //tweak as needed
private var timeLastButtonPressed : float;
function KeyCombo(b : String[]) {
buttons = b;
}
//usage: call this once a frame. when the combo has been completed, it will return true
function Check() : boolean {
if (Time.time > timeLastButtonPressed + allowedTimeBetweenButtons) currentIndex=0;
if (currentIndex < buttons.length) {
if ((buttons[currentIndex] == "down" Input.GetAxisRaw("Vertical") == -1) ||
(buttons[currentIndex] == "up" Input.GetAxisRaw("Vertical") == 1) ||
(buttons[currentIndex] == "left" Input.GetAxisRaw("Vertical") == -1) ||
(buttons[currentIndex] == "right" Input.GetAxisRaw("Horizontal") == 1) ||
(buttons[currentIndex] != "down" buttons[currentIndex] != "up" buttons[currentIndex] != "left" buttons[currentIndex] != "right" Input.GetButtonDown(buttons[currentIndex]) ) {
timeLastButtonPressed = Time.time;
currentIndex++;
}
if (currentIndex >= buttons.length) {
currentIndex = 0;
return true;
}
else return false;
}
var falconPunch : KeyCombo = KeyCombo(["down","right","punch"]);
var falconKick : KeyCombo = KeyCombo(["down", "right", "kick"]);
function Update() {
if (falconPunch.Check()) {
// do the falcon punch
}
if (falconKick.Check()) {
// do the falcon kick
}
}
I want something like that, but it’s a easier way to do this,right ?
Say I press the up button how do I ad this to the array ?
Ok, I have this script. But it’s not working right. The audio is playing very weird. If I play it automatically from the audio source it works, but not when I play it from the script
any ideas ?
var Notes : float[];
var CurNote = 0;
var song1 : AudioClip;
function Start ()
{
Notes = new float[3];
Notes[1] = 5.0;
}
function Update () {
if(Notes ==[0,1,2,0,1,2]){
PlaySong1();
}
}
function PlaySong1(){
audio.PlayOneShot(song1);
}
Have you checked the PlaySong1 is actually getting called (with a Debug.Log, say)? Also, be sure that the value of song1 has been set in the editor. Are you getting any error messages, by the way?
I have no error messages, the sound is playing but it sound very weird 
The sound is just a big mess, a lot of high tones and such things. When I play it automatic without a script it plays nice…
But when I activate it with a script the sound gets messed up. I’m I doing something wrong with the script ?
Is this the right way to play sound from a script.