- Home /
How to make cheat code system like in GTA?
Can someone please help me? I need cheat code system = when I write in example 1234, I will get new gun (gun model will SetActive(true)). I was looking for some tutorials but nothing is here. Thank you...
Answer by megabrobro · Dec 13, 2017 at 02:18 PM
That's too broad a question pal. Because typing '1234' is just a fairly basic form of handling keyboard input. so you just need to check Input.GetKey and make a function create a string that if that matches your cheat code string then it returns true.
Then when that is true, you have to spawn the gun, in the correct position with correct parenting, rotation etc etc and that's where it could get complicated.
Learn in small steps
Thank you I tried it and it works
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class cheatHackCode : $$anonymous$$onoBehaviour {
private string[] cheatCode;
private int index;
public GameObject gun;
void Start() {
cheatCode = new string[] { "a", "b", "c", "d", "e" };
index = 0;
gun.SetActive (false);
}
void Update() {
if (Input.any$$anonymous$$eyDown) {
if (Input.Get$$anonymous$$eyDown(cheatCode[index])) {
index++;
}
else {
index = 0;
}
}
if (index == cheatCode.Length) {
gun.SetActive(true);
}
}
}
Just to clarify something i thought of afterwards. You could 'cheat' a little and use the Unity Text InputField, which is part of the UI stuff. Then the string etc is created for you in the varsomeinputField.text
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unloading Broken Assembly | How to solve this !? 2 Answers
EventTrigger PointerEnter 1 Answer