error cs0131 - The left-hand side of an assignment must be a variable, a property or an indexerplease. help!
please understand that I'm very new to coding and unity but I'm making a endless runner 2d game for ios. i've got a background scroll which won't stop scrolling once the player has died.
so I tried solving that problem with an extra bit of code on the scrolling background script -
public float speed = 0.5f;
public GameObject player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (player.SetActive = false) {
speed = 0.0f;
}
Vector2 offest = new Vector2 (Time.time * speed, 0);
GetComponent<Renderer>().material.mainTextureOffset = offest;
}
}
the error pops up on these lines -
if (player.SetActive = false) {
speed = 0.0f;
}
Can anyone tell me where I went wrong or how to fix it? Or maybe suggest a different way of stopping the background scroll.
I've searched around the internet so far found nothing of help, other answers only led to me having this specific error.
All I want is for the background to stop scrolling once the player has died :(
any help is much appreciated.
GameObject.SetActive() is a function. :-)
There's a default property that lets you check whether something is active in your scene, so your check would become:
if ( player.activeInHierarchy == false )
{
speed = 0.0f;
}
Also (since you are admittedly new to coding), note the use of ==. When comparing whether or not a value equals another value, you will need to use the == notation. A single = is only used when assigning a value.
Answer by roman_sedition · Nov 12, 2016 at 12:50 PM
You could try this out, make a bool which, dictates if the player is dead or alive.
public bool dead;
void Start(){
dead = false;
}
Then when the player dies, assign the bool to true.
dead = true;
In your update you make a check to see if dead is true.
void Update () {
if (dead == true) {
speed = 0.0f;
}
I feel if you are new to this you should probably use bools, it will help you understand how conditional statements work better and makes it easier to step through your code when you debug, and yes as mentioned you should use == if you want to check a condition if something equals a condition. If you are setting your gameobjects as inactive when you are new to this, you might create more problems for yourself.
Thanks for the help and suggestions! I'll keep a lot of this in $$anonymous$$d.
Your answer
Follow this Question
Related Questions
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer
Menu object not responding 0 Answers
I can't figure this out. I have Unity 5.3.1 and this error keeps popping up. error CS0029 1 Answer
"The associated script cannot be loaded." 0 Answers
Error CS0120 : An object reference is required to access non-static member 3 Answers