- Home /
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 ;)
Answer by JPB18 · Jan 02, 2012 at 11:13 PM
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);
Your answer
Follow this Question
Related Questions
How Do I Build My Application To The Size Of The Camera 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Orbit Camera around object 2 Answers
Full screen camera missing? 3 Answers