Hello again, today I'm posting a small but interesting script. It serves to capture sequence of commands from the user to perform certain things.
Here is the function:
Here is the function:
function konamiFunction (incomingKey) // Function from Unity Wiki { var incomingKeyString = incomingKey.ToString(); if (Time.time > timeLastButtonPressed + allowedTimeBetweenButtons) { currentPos=0; } if (currentPos < SequenceKeyCode.length) { if(incomingKeyString==SequenceKeyCode[currentPos]) { timeLastButtonPressed = Time.time; currentPos++; if((currentPos+1)>SequenceKeyCode.length) { inSequence=true; currentPos=0; } } else { currentPos=0; } } }So that's it. Here you can download the fully functioning project.I hope you enjoyed it, give your comments!
I edit some codes to add some simple visual efx when button pressed...
ReplyDeletefunction Update () {
if (inSequence) { // check if the sequence is completed
gameObject.animation.Play();
GameObject.Find("Messages").SetActiveRecursively(true);
}
if (Time.time > timeLastButtonPressed + allowedTimeBetweenButtons)
{
currentPos=0;
toolbarInt=0;
}
}
function konamiFunction (incomingKey) // Function from Unity Wiki
{
var incomingKeyString = incomingKey.ToString();
if (currentPos < SequenceKeyCode.length)
{
if(incomingKeyString==SequenceKeyCode[currentPos])
{
timeLastButtonPressed = Time.time;
currentPos++;
toolbarInt++;
if((currentPos+1)>SequenceKeyCode.length)
{
inSequence=true;
currentPos=0;
toolbarInt=0;
}
}
else
{
currentPos=0;
toolbarInt=0;
}
}
}
Great tutorial! very simple but effective much appreciated. Cheers!
ReplyDeleteThanks for add. This is very appreciated here.
Deleteya arkadaslar androıd dekı oyunlara hıle yapabılırmısınız mesela total conquest
ReplyDeleteUnity 3D is a creative framework for making 3d featured video games and other intelligent substance, for example, compositional visualization's or constant 3d livelinesss. At present, Unity's engineers chip away at Microsoft Windows and Mac OS X, and produce diversions that play on Windows, Mac, Xbox 360, Playstation 3 Wii, ipad and iphone. Diversions likewise take a shot at the Android stage.
ReplyDeleteThis script is really helpful for capturing sequences.
ReplyDelete