- Home /
Game Glitches and Cheat Codes
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
Felipe
[1]: http://answers.unity3d.com/users/11109/aldonaletto.html
[2]: http://answers.unity3d.com/users/17559/fafase.html
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.
Yes, despite their high karma scores, there are other people on UA you know ...
You 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.
What the hell am I doing in this question??!! Next to a guy with 50 times my knowledge!!! That's nice and that's wrong.
Answer by FLASHDENMARK · Apr 09, 2012 at 05:46 PM
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.
Alternatively, he could not use two textfields, and ins$$anonymous$$d do a string.Split in terms of spaces (meaing that it would be inputted like this in a single textfield: gravity 5) and then use parseFloat on element 2 of the returned array.
Answer by by0log1c · Apr 09, 2012 at 06:31 PM
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 = "";
}
}
Thanks it works great - Just a question : The command executed is a script attached to the player right?
When I type nothing in the box, the command still works. Any help?
Answer by $$anonymous$$ · May 01, 2012 at 04:57 PM
Here : unitynoobs you can download a small project with this answer!
Your answer
Follow this Question
Related Questions
how to disable patent components incode 0 Answers
Disable/Enable Buttons and Text plz help jc 1 Answer
Can't enable/disable canvas on Android device 0 Answers
Spotlight help 1 Answer
Disable/Enable Status Bar 2 Answers