Many games like Call of Duty series have glitches and hacks, but GTA has cheat codes. In my game I need a script that has a string value of GRAVITY_5. And when I type that in game a GUI Box will show up saying “Gravity Set To 5”, after the box disappears. After that is typed the players character motor jumping gravity is set to 5. And when if I type that again I’ll get another one saying “Gravity Disabled”, and then disappears. And so as the jumping gravity is set back to original which is 20. Please I need a script
3 Answers
3
Creating a cheat console(in its basic form) is very easy. Since you ask for a script I won’t give you one, you will have to figure out the details yourself.
First of you will have to utilize Unity’s GUI system.
Create two textfields one where you input the name of the variable you want to change(e.g. gravity). Then in the other textfield you input what the variable should be set to.
You should now figure out what the player inputted and what he wanted the inputted variable to be. E.g if the keyword “gravity” is inputted and the other keyword “5” is inputted, you should change the gravity to 5.
You can use parseFloat(stringName) to convert the variable amount from a string to a number.
UnityScript’s eval will evaluate a string like it was compiled code. You should know that it uses reflection(?) behind the scene and is quite expensive, not for everyday use. What’s awesome about it is you don’t need to prepare statements so I use it to debug variable state at runtime and such.
Simplified, untested version of what I use:
public var debugKey:KeyCode = KeyCode.F11;
public var show:boolean = false;
public var command:String = "";
function Update()
{
if(Input.GetKeyDown(debugKey))
show = !show;
}
function OnGUI()
{
if(!show)
return;
command = GUILayout.TextField(command);
if(GUILayout.Button("Execute"))
{
eval(command);
command = "";
}
}
Here : unitynoobs you can download a small project with this answer!
Do not target UnityAnswers users. It seems very rude to me. That being said, take a look at UnityScript eval() function. I made myself a hack console using that.
– by0log1cYes, despite their high karma scores, there are other people on UA you know ...
– KleptomaniacYou need a script? Of course you do, but don't ask for them, that is not very good etiquette. And also, Aldonaletto and fafase are helpful people and talented at that, but there are plenty of others on this site that could help you, not just them.
– FLASHDENMARKWhat the hell am I doing in this question??!! Next to a guy with 50 times my knowledge!!! That's nice and that's wrong.
– fafase