Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Draw GUI behind some 3D-Object

Discussion in 'Immediate Mode GUI (IMGUI)' started by Elessar Elanesse, Apr 16, 2014.

  1. Elessar Elanesse

    Elessar Elanesse

    Joined:
    Jan 9, 2014
    Posts:
    7
    Hello all !

    I'm in trouble with a GUITexture. ='(

    I want to show off my GUITexture next to a Interactive 3D Object, when I trigger it...
    I use this Script to move my GUITexture next to my 3D Object :

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Btn_Action : MonoBehaviour {
    5.  
    6.     public Transform target;
    7.     private Vector3 wantedPosition;
    8.     private Vector3 positionReal;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.         positionReal = new Vector3(target.position.x,target.position.y+0.5f,target.position.z);
    18.         wantedPosition = Camera.main.WorldToViewportPoint(positionReal);
    19.         transform.position = wantedPosition;
    20.     }
    21. }
    My problem is that the GUITexture is in front of all my 3D Object... I tried with this Tuto :
    unity3d-creating-a-gui-with-both-3d-and-2d-elements

    But it's didn't work... (I modified my Script for use the Second Camera) - GUITexture who don't follow my Target, everytime in front of my 3D-Objects...

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Btn_Action : MonoBehaviour {
    5.  
    6.     public Transform target;
    7.     private Camera camera;
    8.     private Vector3 wantedPosition;
    9.     private Vector3 positionReal;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.    
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.         if(camera == null)
    19.         {
    20.             camera = GameObject.FindWithTag("CameraBtn").camera;
    21.         }
    22.         positionReal = new Vector3(target.position.x,target.position.y+0.5f,target.position.z);
    23.         wantedPosition = camera.WorldToViewportPoint(positionReal);
    24.         transform.position = wantedPosition;
    25.     }
    26. }

    Need Help !! Thanks =)