Hi,
I need to create a simple code for an object to activate on a ‘key’ press only, otherwise always it should be deactivated.
The problem I have is that it doesn’t functions as I wanted, instead it toggles, pressing key results into activation on and another press make the object deactivate. All I need is just one press key activate object and deactivate when I lift the key up. Also tried GetKeyDown()
and GetKeyUp()
but it ends up toggling it.
Here’s my non-working code:
void Update () {
animObject.SetActive(false);
if (Input.GetKeyDown(KeyCode.Space))
{
animObject.SetActive(true);
Application.CaptureScreenshot("screeshot.png");
}
}
My purpose : Is to take a screenshot of the object while key is pressed and take a screenshot of it, and then deactivate object such that it doesn’t seen on a visible scale, The object must be invisible (deactivated) all the time.
Thanks