GUITexture Problems

I’m trying to create an icon that appears on the screen when the middle mouse button is pressed in the same location. Similar to pressing a middle mouse button in a web browser. If the button is held down it allows the player to pan the camera (rts style) and the icon will show where they started so that when they move the mouse to the other side of the icon the camera will pan the other way.

I looked at a few tutorials and i think i must be missing some basic info as i’m just having trouble.

this piece of code is inside my update function.

public Texture2D panicon; //is actually before the update function



guiTexture.texture = panicon;
guiTexture.pixelInset = new Rect(startMX, startMY, 32, 32);


panning is true when the middle mouse button is held down and startMX/MY are the pixel x and y where the mouse was pressed. as far as i’m aware, the first 2 variables in the pixelInset Rect are for the positioning which i can slightly adjust later.

in the editor i have linked my basic texture to the public texture variable.

i am also getting the error:

MissingComponentException: There is no ‘GUITexture’ attached to the “Main Camera” game object, but a script is trying to access it.
You probably need to add a GUITexture to the game object “Main Camera”. Or your script needs to check if the component is attached before using it.

i don’t quite understand this error and a search with it only shows irrelevant topics.

any help or pointers would be appreciated.

I’m assuming this code is on your camera update function. You don’t have a reference to the guiTexture. You either need to find it in hierarchy, or locate it with a name, or make a public variable and add a guiTexture gameobject to that variable in the inspector. You could also add a guiTexture component to your camera in the inspector that you want to work with.

here is the documentation page for traversing game objects to get references: