i neew help with error. Assets\Stamina.cs(47,25): error CS1001: Identifier expected

this is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.FirstPerson;

public class Stamina : MonoBehaviour
{
public Slider staminaBar;

private int maxStamina = 100;
private float currentStamina;

private WaitForSeconds regenTick = new WaitForSeconds(0.1f);
private Coroutine regen;

public static Stamina instance;

public PlayerMovement player;

private void Awake()
{
instance = this;
}

// Start is called before the first frame update
void Start()
{
currentStamina = maxStamina;
staminaBar.maxValue = maxStamina;
staminaBar.value = maxStamina;
}

// Update is called once per frame
void Update()
{

}

public void UseStamina(float amount)
{
if(currentStamina - amount >= 0)
{
currentStamina .= amount;
staminaBar.value = currentStamina;

if(regen != null)
{
StopCoroutine(regen);
}
regen = StartCoroutine(regenStamina());

}
}
private IEnumerator RegenStamina()
{
yield return new WaitForSeconds(5);

while (currentStamina < maxStamina)
{
currentStamina += maxStamina / 100;
staminaBar.value = currentStamina;
yield return regenTick;
}
}
}

Without code tags, I couldn’t even tell you what line your error actually points to.
However, I can tell you this is most likely a typo. Go to line 47(where the error points) and start from there. If that line looks fine, look at the line before and after. Typos sometimes affect the lines around them.

There are even probably red squiggles to help you out.

As above, please edit your post to use code-tags .

I do see an errant dot in currentStamina .= amount.

1 Like

That’s nice. Here is how to understand error messages and fix your own typos:

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

And as others note, if you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

You can edit your post above.

I’m pretty sure it should be

currentStamina -= amount;

given the method name