Activating a GUITexture by clicking on an object (script in c#)?

Hi everyone,

I am new in coding and unity in general. I am working on a simulation, scripted in c#, and I want that the player is able to click on an object and get more information about that object in a popup. The popup must consist of a PNG(homemade (name: clickonme)) and a cross in a small box(generated by Unity) to exit the popup. In this picture (see attachments if this is too small to read)

you can see the errors that Unity indicates (MonoDevelop says that there are no errors), I have obviously done something wrong and I think that the thing that goes wrong is me not knowing how to tell Unity which file(the PNG) to use. (I really don’t know how to formulate this better sorry)

So if someone knows how to correct this that would be great!

Thanks for replying and you can always ask me if I forgot some information!

This is my code:

using UnityEngine;
using System.Collections;

public class onclickGUI : MonoBehaviour {
	
	// Use this for initialization
	private bool PopUp;
	public string Info;
	public GUITexture clickonme;

	void OnMouseDown()
	{
		PopUp = true;
	}
	
	void DrawInfo()
	{
		if(!clickonme)
		{
			Debug.LogError (clickonme);
			return;
		}
		GUI.DrawTexture(Rect(50,50,250,250), clickonme, ScaleMode.ScaleToFit, true, 10.0f);
		Rect close = new Rect (250,50,50,50);
		if (PopUp)
		{
			GUI.Box(Rect, Info);
			if (GUI.Button (close,"X"))
			{
				PopUp = false;
			}
		}
	}
	void OnGUI()
	{
		DrawInfo();
	}
}

Not sure how MonoDevelop didn’t throw an error due to using a Rect type wrong in GUI.DrawTexture.

I don’t know what size & position you wanted for the Info Box, so i made up some values in the new Rect. DrawTexture takes a Texture type, not a GUITexture, you were missing the new keyword on line:23.

Here you go, modify as needed:

using UnityEngine;
using System.Collections;

public class onclickGUI : MonoBehaviour {
	
	// Use this for initialization
	private bool PopUp;
	public string Info;
	public Texture clickonme;
	
	void OnMouseDown()
	{
		PopUp = true;
	}
	
	void DrawInfo()
	{
		if(!clickonme)
		{
			Debug.LogError (clickonme);
			return;
		}
		GUI.DrawTexture(new Rect(50,50,250,250), clickonme, ScaleMode.ScaleToFit, true, 10.0f);
		Rect close = new Rect (250,50,50,50);
		if (PopUp)
		{
			GUI.Box(new Rect(100, 50, 100, 50), Info);
			if (GUI.Button (close,"X"))
			{
				PopUp = false;
			}
		}
	}
	void OnGUI()
	{
		DrawInfo();
	}
}

You need to fix all this script errors indicated by unity3d before run your scene. For each error ready carefully, look the code, search in the internet, change and fix.