Health Regeneration Script Please Help!!!

I have written a script for health regeneration but it is saying it needs “;” at the end of line 8 when it already has one please help.

  private var IsReviving:boolean = true;
    
    function Update()
    {
    	if (IsReviving)
    		{
    			IsReviving = false;
    			Yield WaitForSeconds(10);
    			HealthScript.Health += 1;
    			IsReviving = true;
    		}
    	}
    }

I believe it might be because you have a capitol Y in Yield.

Try it with a lowercase Y. For reference: Unity - Scripting API: WaitForSeconds

Try this:

  private var IsReviving:boolean = true;
    
    function Update(){
        if (IsReviving){
                IsReviving = false;
                yield WaitForSeconds(10);
                HealthScript.Health += 1;
                IsReviving = true;
        }
    }

One too many close brackets, and a capital Y as mentioned by AlteredReality. As for all the other code, I know everyone has their own style, but I find variables starting with capital letters confusing. I reserve those for function names and classes - it makes things much more readable in my opinion.

Can you actually do a yield in Update? Why not just call another method?

void Start()
{
    StartCoroutine(RegenerationHandler());
}

public float tickTime = 2;
public float tickAmount = 2;
public float myHealthAmount = 0;
private IEnumerator RegenerationHandler()
{
   while(true)
   {
       myHealthAmount+= tickAmount;
       yield return new WaitForSeconds(tickTime);
    }
}

With UnityScript… Leave out the return new… and declare your variables as normal. Should work though.

Good point! :wink: