- Home /
Question is off-topic or not relevant
How to disappear an object and get input from user?
Hi guys, I'm trying to write a code to disappear my object at a certain time and show it when the user press the key from keyboard. I have trouble with using " obj.SetActive(false) " I'm trying to use " if (Input.GetKeyDown(KeyCode.A)) " after " obj.SetActive(false) " but it doesn't run or even doesn't show an error! I know the problem is " obj.SetActive(false) " , but I don't know how to fix it. I would appreciate it if u help me =))! here is the code:
if (elapsed_time >= 4) //to disappear the car after 4s
{
car.SetActive(false); // SetActive(false) to disappear the car
if (Input.GetKeyDown(KeyCode.A)) //getting input from user to show the car and the result
{
ShowAndHide(car,0.5f); //introduced at the beginning of the script (go = car, delay = 0.5s)
print("user pressed the key:" + elapsed_time); //printing the measured time on the screen
}
}
RE$$anonymous$$A$$anonymous$$E THE POST USING THE CODE SA$$anonymous$$PLER BUTON
I assume the script is mapped on the car object, and thus setting the object inactive, also sets the script inactive which is why it doesn't work anymore. You have to map the script somewhere else, and reference the car through the inspector or something else.
Follow this Question
Related Questions
How to make enemy chase for longer distances than it's initial "notice" range 2 Answers
How can I instantiate one shot over another? 1 Answer
How to shorten multiple if statements ? 2 Answers
Object flashing in and out every frame (because of my script) 0 Answers
Spatial Anchors not saving correctly??? 0 Answers