Error unity error CS0200: Property or indexer `UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController.Running' cannot be assigned to (it is read only)
public class PlayerController : MonoBehaviour {
public float playerHealth = 100f, maxPlayerHealth = 100f, playerStrength = 100f, maxPlayerStrength = 100f, playerHungry = 100f, maxPlayerHungry = 100f, playerThirst = 100f, maxPlayerThirst = 100f;
public bool cantRunWithoutStrength = true;
public float healthRegeneration = 0.1f, strengthRegeneration = 0.1f, hungryDownspeed = 0.001f, thirstDownspeed = 0.001f, runExpensOfStrength = 0.04f, hungryDamagePerSec = 0.25f, thirstDamagePerSecond = 0.15f;
public Image hpBar, strBar, hungBar, thirBar;
RigidbodyFirstPersonController fpc;
float maxBarLength = 256f;
float lastHPTimer = 0f, lastHUNGTimer = 0f, lastTHIRTimer = 0f, lastTHIRSTDamage = 0f, lastHUNGRYDamage = 0f;
void Start()
{
fpc = gameObject.GetComponent<RigidbodyFirstPersonController>();
UpdateBars();
maxBarLength = hpBar.rectTransform.sizeDelta.x;
}
public void ShowPlayerInfo(bool show)
{
hpBar.transform.parent.parent.gameObject.SetActive(show);
}
void Update()
{
if (!fpc.Running)
{
playerStrength -= runExpensOfStrength;
playerStrength = Mathf.Clamp(playerStrength, 0, maxPlayerStrength);
UpdStrength();
}
if (cantRunWithoutStrength)
{
if (playerStrength < 10f)
{
fpc.Running = false;
}
else
{
fpc.Running = true;
}
}
Answer by Dave-Carlile · Nov 20, 2015 at 07:31 PM
The error is quite specific. The Running
property can't be assigned to because it's read only. On lines 34 and 38 you're trying to set fpc.Running
to true or false. There might be a method on the object or some other setting that lets the object know when to change the value of Running, but you aren't able to do it yourself in the way you're trying to.
I don't see any documentation for it, so can't help you much beyond that. Look for other properties or methods on the object that might let you control Running in some way. Might be something like SetRunning or something.
Your answer

Follow this Question
Related Questions
Sign In Error 0 Answers
Unity Firebase Google SignIn Error Help 0 Answers
CS1513 and CS1022 problem 1 Answer
Object Reference not set to an instance of an object for Moving Platform 0 Answers