Re: Unlock Cheats

Useful script from community for unity 3d.
Post Reply
User avatar
Lovatto
Admin
Admin
Posts: 1052
Joined: Sun Dec 07, 2014 3:18 pm
Contact:

Sat Jan 30, 2016 4:30 pm

a very simple code for any type of game you want to give some advantage to players when they write a certain word, GTA style.

Enjoy!

Code: Select all

using UnityEngine;

public class Cheats : MonoBehaviour
{
/// <summary>
/// 
/// </summary>
public string[] m_Code;
//Privates
private int index;

/// <summary>
/// 
/// </summary>
void Start()
{
//change this word for your code word
m_Code = new string[] { "y", "o", "u", "r", "c", "o", "d", "e"};//the example code is "yourcode".
//start index from
index = 0;
}

/// <summary>
/// 
/// </summary>
void Update()
{
//if no keypress is detected
if (!Input.anyKeyDown)
return;
//if the key is pressed with the same name of current char of cheat code...
if (Input.GetKeyDown(m_Code[index]))
{
index++;//continue with the next char
}
else
{
index = 0;//return to firts char
}

if (index == m_Code.Length)//is complete word
{
Debug.Log("Cheat unlocked!");
//Your Function here
//Example MorePower();
index = 0;//return to first char again (optional).
}
}

}
Post Reply