- Home /
GUI.Drawtexture Overlaping Other GUI.Drawtexture.
Hey There,
I've have spent some time writing an Achievement script using GUI.Drawtexture for a game I'm working on at University. An I have run into some trouble an I'm hoping someone here may be able to help me. Essentially, the script I have renders a GUI.Drawtexture when a specific condition is made, though when two conditions are achieved at the same time the script will only draw one of the textures instead of one after the other or both at the same time. Any help would be great and thank you in Advanced.
Here is the code I am currently working on (I'm using Javascript):
Also, the youGotAchivement, is called in another script.
#pragma strict
var textureH : int = 150; // Texture Height
var textureW : int = 100; // Texture Width
var textures: Texture2D[];; // 2D Texture Array for Challanges
static var youGotAchievement01 : boolean; // Turns on/off Achievement - Hold Combo for 10 Seconds
static var youGotAchievement02 : boolean; // Turns on/off Achievement - Remain Untouched for 5 Seconds
static var youGotAchievement03 : boolean; // Turns on/off Achievement - Kill 5 Enemies in 2 Seconds
private var originalWidth = 2560.0; // define here the original resolution
private var originalHeight = 1440.0; // you used to create the GUI contents
private var scale : Vector3;
function Start ()
{
Destroy (gameObject, 3);
}
function OnGUI()
{
scale.x = Screen.width/originalWidth; // calculate hor scale
scale.y = Screen.height/originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
// substitute matrix - only scale is altered from standard
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
if(youGotAchievement01 == true)
{
GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth ) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[0]); // enable texture
}
if(youGotAchievement02 == true)
{
GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth ) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[1]); // enable texture
}
if(youGotAchievement03 == true)
{
GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), textures[2]); // enable texture
}
GUI.matrix = svMat; // restore matrix
}
Well, you're drawing them all in the exact same position, so how do you expect to see more than one at a time?
Please explain in more detail what you expect to happen when more than one condition is true.
Say the player unlocks 2 achievements at the same time, I want to have it so that one achievement will pop up for the set time, then followed by the other achievement that was unlocked.
Answer by Tomer-Barkan · Dec 01, 2013 at 11:58 AM
What you can do, is keep a list of all the achievements that you want to show, and show them one after another for a set amount of time. I'm not strong in javascript, but I'll try:
private var achievements : Texture2D[];
private var displayedAchievement : Texture2D = null;
private var displayAchievementUntil : float = 0;
private var displayTime : float = 3;
function AddAchievement(texture : Texture2D) {
achievements.push(texture);
}
function OnGUI() {
if (Time.time >= displayAchievementUntil && displayedAchievement != null) {
// stop displaying achievement
displayedAchievement = null;
}
if (displayedAchievement == null && achievements.length > 0) {
// display next achievement
displayedAchievement = achievements[0];
achievements.splice(0, 1);
displayAchievementUntil = Time.time + displayTime;
}
if (displayedAchievement != null) {
// display achievement texture
GUI.DrawTexture(new Rect(Screen.width / originalWidth + (originalWidth) - 150,Screen.height / originalHeight + (originalHeight ) - 100,textureH, textureW), displayedAchievement);
}
}
Call AddAchievement
with the texture of the achievement you want to dispaly. It will automatically display it for displayTime
seconds and then display the next one.
Your answer
Follow this Question
Related Questions
Texture on center bottom of screen 3 Answers
Setting Scroll View Width GUILayout 1 Answer
How to change rect size? 2 Answers