Hello World!


Hello World!

Hello everyone, I'm creating this blog with the purpose of sharing my and your ideas with all hungry for game development.

Follow Tweeter

empty space


Tuesday, May 1, 2012

Sequences like Cheat Codes - Unity 3D

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:


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!


5 comments:

  1. I edit some codes to add some simple visual efx when button pressed...

    function 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;
    }
    }
    }

    ReplyDelete
  2. Great tutorial! very simple but effective much appreciated. Cheers!

    ReplyDelete
    Replies
    1. Thanks for add. This is very appreciated here.

      Delete
  3. ya arkadaslar androıd dekı oyunlara hıle yapabılırmısınız mesela total conquest

    ReplyDelete
  4. Unity 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.

    ReplyDelete