- Home /
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class gameScript : MonoBehaviour {
public GameObject playerInfoScreen;
// Use this for initialization
void Start ()
{
playerInfoScreen = playerInfoScreen.GetComponent<GameObject> ();
}
public void infoEnable()
{
playerInfoScreen.SetActive = true;
}
public void infoDisable()
{
playerInfoScreen.SetActive = false;
}
}
I get this error : The left-hand side of an assignment must be a variable, a property or an indexer already tried everything, searched forum, google and tried posting here.
Any ideas how to fix ? I am newbie in Unity
Answer by saschandroid · Aug 16, 2016 at 05:52 AM
It's
playerInfoScreen.SetActive(false);
or
playerInfoScreen.SetActive(true);
Answer by Whiteleaf · Aug 16, 2016 at 05:09 AM
It's probably because your assigning a variable to to that same variable, but it hasn't been assigned yet.
Or it's because GameObject isn't a component.
Answer by Salman_Saleem · Aug 16, 2016 at 07:01 AM
SetActive is a method of GameObject, so you cannot assign a value to it. You have to pass parameter in it
Use it like this.
playerInfoScreen.SetActive(true);
playerInfoScreen.SetActive(false);
Your answer
Follow this Question
Related Questions
Load a GameObject that is outside of script and set it active at the same time 1 Answer
How to set game objects as inactive via button 1 Answer
GameObject.setActive(bool) is not activating my gameObject 1 Answer
Displaying a static variable from another script with OnGUI 1 Answer
Script won't reactivate after I deactivate it through a script 1 Answer