Just recently, we added a static GUI crosshair in the middle of the screen. But what if we wanted to put the gun down, and then lift it to iron sight aim like every fucking game made after 2000? Well, I'm not sure I have the finesse to make this work in a practical sense, but let me speculate for a moment.
So we've got our GUI:
var crosshairTexture : Texture2D;
var position : Rect;
function Start()
{
position = Rect( ( Screen.width - crosshairTexture.width ) / 2,
( Screen.height - crosshairTexture.height ) / 2,
crosshairTexture.width, crosshairTexture.height );
}
function OnGUI()
{
GUI.DrawTexture(position, crosshairTexture);
}
We want to add a button command, which means it needs to go in an Update() function, calling to the logic every frame.
var crosshairTexture : Texture2D;
var position : Rect;
function Update()
{
if( Input.GetButtonDown( "Aim1" ) )
{
}
function Start()
{
position = Rect( ( Screen.width - crosshairTexture.width ) / 2,
( Screen.height - crosshairTexture.height ) / 2,
crosshairTexture.width, crosshairTexture.height );
}
function OnGUI()
{
GUI.DrawTexture(position, crosshairTexture);
}
...That's all I have on that for the moment...
No comments:
Post a Comment