Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Puting a texture behind another one

Discussion in 'Scripting' started by cruising, Aug 8, 2014.

  1. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Hello!

    I have made some textures for my compass, one for the actual compass and one frame for it with a transparent
    bow/hole in the middle so you only see the current direction N W S E.

    However, my problem is that the NWSE textures covers the the frame and not vice versa, the frame should cover the compass.

    Is there a way to determine what texture should be on top and on the background?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Of course, but it depends on what method you're using for drawing the compass.

    --Eric
     
  3. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    This is what i use for the compass drawings
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CompassFrame : MonoBehaviour {
    5.     public Texture bTexture;
    6.     public Texture aTexture;
    7.     void OnGUI() {
    8.         if (Event.current.type.Equals(EventType.Repaint))
    9.             Graphics.DrawTexture(new Rect(0, 740, 485, 150), bTexture);
    10.             Graphics.DrawTexture(new Rect(794, 0, 330, 50), aTexture);
    11.      
    12.     }
    13. }
    EDIT: the texture B dont go for the compass, thats a box for the chat, i putted it there just to collect texturedrawings in same script, the texturedrawing for the compass is in the actual compass script, but i still want the aTexture to on top no matter other texture there is on the screen
     
    Last edited: Aug 8, 2014
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Your if statement is only affecting the following line, since you're not using braces. But you should use GUI.DrawTexture in OnGUI anyway (and get rid of the if statement). Within the same OnGUI function, stuff is drawn in the order that the code runs, so later things will be drawn on top of earlier things.

    --Eric
     
  5. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Thanks!
    That works as it should do!