Home c# How in GameObject.SetActive (BOOL) Transfer a negative value parameter to Unity C...

How in GameObject.SetActive (BOOL) Transfer a negative value parameter to Unity C #?

Author

Date

Category

On the scene I have GameObject Cube , and there is still a code in which the cube “turns off” when you press the D key like this:

if (input.ketkeyup (keycode.d))
  {
    Cube.SetActive (False);
  }

But I want the cube to be disconnected and turned on on the same key, in the theory it is necessary that, each time clicking on D, SetActive has received the parameter of the current opposite value by the value of the value, but how to write this parameter concept does not have


Answer 1, Authority 100%

You can use the property gameobject.activeself :

cube.setActive (! cube.activeself);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions