using UnityEngine;
using System.Collections;
public class Questshower : MonoBehaviour {
public Texture Instruction;
void OnGUI()
{
if (Input.GetKeyDown("i"))
{
GUI.DrawTexture(new Rect(Screen.width / 2 , Screen.height / 2 ,1024,752), Instruction);
}
}
}
I want to render a texture when I pressed i exactly in the middle of screen and with this size ( 1024752 ) … and then when keyup the texture disappear…I don’t know how to give the size! I used tens of numbers but it didn’t work! summary :
when key “I” down :
render texture (Instruction… that’s is public field ) exactly in the middle of screen with size of 1024752 … and when the I released (getkeyup) the texture disappear… what should I do?
First thing I noticed is you’re using GetKeyDown() this returns true only on the frame when the key is pressed, if you want it to be true every frame that the button is held down then use GetKey()
Second thing is the Rect that you define in the DrawTexture call uses half the screen width/height to get its origin but it is sized manually. This could be wrong depending on what you are trying to do:
If you want the Image to always be 1024x752 no matter what the screen resolution is:
You should make the origin half of the image size away from the center of the screen
var size : Vector2 = new Vector2(1024, 752); // we put the size here because we'll use it more than once on the next line
new Rect(Screen.width/2 - size.x/2, Screen.height/2 - size.y/2, size.x, size.y);