- Home /
I am trying to send a 2D texture to my first person controller to display on the GUI
I have a function on an object to send a message with a 2d Texture to my first person controller and then for the first person controller to display that 2d texture on the GUI. Currently it sends and receives the picture with no errors. However I can't get the game to actually display the picture.
Here is the code for the object that is sending the picture.
using UnityEngine;
using System.Collections;
public class sendPicture: MonoBehaviour {
public Texture2D picture;
public GameObject target;
void OnMouseDown(){
Debug.Log("click"); target.SendMessage("DisplayPicture",picture);
}
}
This is the code for the first person controller
using UnityEngine;
using System.Collections;
public class openPicture : MonoBehaviour {
public GUITexture Hud;
void DisplayPicture(Texture2D picture){
Debug.Log("recieved");
Hud.enabled = true;
Hud.texture = picture;
}
}
P.S: I have a GUI Texture component on the first person controller.
Answer by FunkyL1zard · Feb 05, 2014 at 05:13 PM
Its not displaying the picture because the GUI Texture component has to be at position 0.5, 0.5, 0. To display in the center of the screen and your first person controller is probably not at the right position. So you should add a GUI Texture component to an empty game object located at position 0.5, 0.5, 0 and set it as a chilled to the first person controller. You can then use GameObject.GetComponent in void Awake().
$$anonymous$$ake sure the transform position is 0.5, 0.5, 0 before you add it to the First Person Controller.
Your answer
Follow this Question
Related Questions
NotificationCenter Help Needed 0 Answers
Setting Scroll View Width GUILayout 1 Answer
Draw GUI texture from it's center point. 2 Answers
UFPS:ultimate fps cameraGUI texture wont show in game 0 Answers