How to temporarily disable an object

Asked 1 years ago, Updated 1 years ago, 76 views


Don't hide the object, make it unusable until n seconds later. I'd like to make it a specification, but is there a way?

c# unity3d

2022-09-30 19:23

3 Answers

I still don't know what "disable" means, but I think it's better to put a script on the object (if any) and put the flag "Processing in progress" in order to determine "Unprocessable Time".

bool isActive=false;

public void StartAction() {
    if(isActive) return;// Do nothing because it is "Processing"

    StartCoroutine (DoAction());
}

Enumerator DoAction() {
    isActive = true;

    // Something to do with it

    yield return new WaitForSeconds (10.0f); // 10 seconds
    isActive=false;
}


2022-09-30 19:23

Why don't you copy the object and put it back in n seconds?


2022-09-30 19:23

Why don't you record the time you last ran on the static member and implement it in a way that allows you to wait when running the method compared to the current time?
It might be a little complicated when there are multiple objects at once...


2022-09-30 19:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.