Reputation: 11
I want to make an invisible object visible when I type the word I chose in my game, how can I do that?
Upvotes: 0
Views: 94
Reputation: 2720
Making an invisible object visible is generally easy — just start with its renderer disabled and then enable it for example.
GetComponent<Renderer>().enabled = true;
(This may vary slightly for e.g. a sprite.)
For the second part, assuming you mean something like a cheat code where the game is accepting normal control input without anything like an input field, but pressing a specific combination of keys will activate a secret function, I think something like this should work:
string cheatCode = “magiceye”;
int index=0;
void Update()
{
foreach(char c in Input.inputString) {
if( c == cheatCode[index] )
index++;
else
index=0; // Reset if a wrong key is typed
if( index == cheatCode.Length ) {
RevealInvisibleObject(); // Full cheat code was entered uninterrupted
index=0;
}
}
}
Upvotes: 0