Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using an IEnumerator to change multiple booleans for example (Frozen to be false)


C#
public void ChangeStatus(ref bool status)
 {
 
     if(status == true)
     {
         TimeDelay(status);
 
     }
 }
 
 public IEnumerator TimeDelay(bool status)
 {
     yield return new WaitForSeconds(ResistanceLevel);
 
     status = false;
 
 }


I can not pass an argument using REF in an IEnumerator so my program is not working.

Any Solutions Thank you.

Unity2d,C#

What I have tried:

I have tried thread.sleep but that stops the whole game.
Posted
Updated 26-Oct-18 19:44pm
Comments
Dave Kreskowiak 26-Oct-18 15:39pm    
Not enough information. You're going to have to provide a LOT more detail about what you're doing and the appropriate code you've got behind it.

1 solution

status is not a "global variable" (there are no such things in C# by design, although static variables do allow you to approximate them) - it is a local parameter variable, and is only accessible inside the ChangeStatus method, it's location in memory is not fixed and will vary while the app is running because it is placed on the stack immediately before the method is called.

You cannot do what you want to: I think you need to rethink your whole approach here, but I can;t tell you what to do as I have no idea why you would think this would be a good solution to whatever problem you are trying to solve!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900