x


Texture not showing

Hello there!

So, I've this C# script to print a texture in the camera, and resize the texture according with the size of the screen, having the base resolution with 1080px of height. But somehow the texture doesn't show up. Here's the code:

using UnityEngine; using System.Collections;

public class GuiScript : MonoBehaviour { public Texture LeftTexture; public Texture HpTexture; public float LeftTextHeight = 316; // public float LeftTextWidth = 356; public float Padding = 2; // Use this for initialization void Start () {

}

// Update is called once per frame
void Update () {

}

//GUI Design
void OnGUI () {
    if (!LeftTexture || !HpTexture) {
        Debug.LogError("Assign a Texture in the inspector.");
        return;
    }

     float SizeRelate = Screen.height/1080;
     GUI.DrawTexture(new Rect(Padding, Screen.height - ((LeftTextHeight * SizeRelate) + Padding), LeftTextWidth * SizeRelate, LeftTextHeight * SizeRelate), LeftTexture, ScaleMode.ScaleToFit, true, 0);



}

}

And thanks for the help ;)

more ▼

asked Jan 02 '12 at 12:44 AM

JPB18 gravatar image

JPB18
74 11 18 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Oh well, never mind, found the answer, just needed to create a new variable with the value of screen.height inside:

Measuring Screen and HUD Ratio float ScreenHeight = Screen.height; float ScreenWidth = Screen.width; float SizeHeightRelate = ScreenHeight/1080; float SizeWidthRelate = ScreenWidth/1900;

    //Measuring Left HUD Size
    float XLeft = Padding;
    float YLeft = ScreenHeight - ((LeftTextHeight * SizeHeightRelate) + Padding);
    float WLeft = LeftTextWidth * SizeWidthRelate;
    float HLeft = LeftTextHeight * SizeHeightRelate;

    //Show HUD
    GUI.DrawTexture(new Rect(XLeft, YLeft, WLeft, HLeft), LeftTexture, ScaleMode.ScaleToFit, true, 0);
more ▼

answered Jan 02 '12 at 11:13 PM

JPB18 gravatar image

JPB18
74 11 18 23

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4168
x3013
x391
x90
x3

asked: Jan 02 '12 at 12:44 AM

Seen: 538 times

Last Updated: Jan 02 '12 at 11:14 PM