public to private errors

Hi Rookie question: In the follow script I want to delete a panelInfo variable from the Inspector, make it private but I got many errors when change to private.
I can not figure out how to set panelInfo.SetActive (true) for a private variable :frowning:
Any tips are welcome…
Just updated with some tips from nice users, but still is not working
I get errors in panelInfo.SetActive(true); panelInfo.SetActive(false);
Thanks for your help :slight_smile:

using UnityEngine;
using System.Collections;

	public class HighlightBlue : MonoBehaviour {
	public Color selectedColor;
	public Texture2D partInfo;

	[HideInInspector]
	public GameObject panelInfo;

	
	void Start(){
		panelInfo = GameObject.FindWithTag("panelInfo");
		panelInfo.SetActive(false);
	}
		public void myColorChange(Color col) {
		GameObject[] fullG = GameObject.FindGameObjectsWithTag(“Blue”);
		foreach(GameObject gmo in fullG) {
			gmo.renderer.material.color = col;
		}
	}
	
	void OnTouchDown () {
	
		this.myColorChange(selectedColor);
		panelInfo.SetActive(true);
		panelInfo.renderer.material.mainTexture = partInfo;
	}
	
	void OnTouchUp () {
		this.myColorChange(Color.white);
		panelInfo.SetActive(false);
	}
	
	void OnTouchStay () {
		this.myColorChange(selectedColor);
		panelInfo.SetActive(true);
		panelInfo.renderer.material.mainTexture = partInfo;
	}
	
	void OnTouchExit () {
		this.myColorChange(Color.white);
		panelInfo.SetActive(false);
	}
}

If you want to hide it in the inspector but remain it public because other scripts are accessing it or whatever just put [HideInInspector] on top of the variable.

[HideInInspector]
public GameObject panelInfo;

Obviously if you do this you will lose any reference you have pass to it in the inspector so you will have to give it a value in other way, for example finding the GameObject by tag or by name:

void Start()
{
    panelInfo = GameObject.Find("YourGameObjectName");
    panelInfo.SetActive(false);
}

or

void Start()
{
    panelInfo = GameObject.FindWithTag("YourTag");
    panelInfo.SetActive(false);
}

If you set the panelInfo to private your stopping Unity from serializing it, or in other words saving the value.

If you want a private panelInfo then the easiest way is to assign a tag for your panelInfo gameobject then the first line of start should read:

panelInfo = GameObject.FindGameObjectWithTag("myTagName");

put that above SetActive(true);

If you feel lazy when trying to fix the errors (not recommended :slight_smile: you can just keep the variable public and hide it from the inspector:

[HideInInspector]
public GameObject panelInfo;