- Home /
Crosshair Aiming Issue, Simple, Yet Confusing.
Hey guys,
I am currently having an issue with a simple script I wrote, as GUI does not allow " yield WaitForSeconds", I had to create two GameObjects with two different crosshairs. One of the crosshair is used for shooting from the hip (NormalCrosshair) and the other allow the player to aim at an object and shoot (FocusCrosshair).
The problem is, whenever I am aiming (FocusCrosshair) and press the shoot button (Fire1), the other crosshair (NormalCrosshair)is shown on the screen along with the other aim(FocusCrosshair).
Is there any possibilities of using left mouse key (Fire1) to shoot from the hip and when the player is aiming with the right mouse key (Key1) and press the left mouse key (Fire1), it won't show the other crosshair (NormalCrosshair).
Thanks everyone, the script can be found below:
P.s. Sorry for bad english, been working on this project for the past 7 hours and it's 2:33am.
#pragma strict
var NormalCrosshair : GameObject; //Normal Crosshair
var FocusCrosshair : GameObject; //Aim Crosshair
function Start()
{
//On-load Disable GameObject
NormalCrosshair.active = false;
FocusCrosshair.active = false;
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
//Shoot without Aiming but still show a Crosshair (See NormalCrosshairExecute function)
NormalCrosshairExecute();
Debug.Log("Normal Crosshair Executed");
}
if(Input.GetButtonDown("Fire2"))
{
//Aim Activated with Right Mouse Click
FocusCrosshair.active = true;
Debug.Log("Focus Crosshair Active");
}
else if (Input.GetButtonUp("Fire2"))
{
//Aim Deactivated on Button Release
FocusCrosshair.active = false;
Debug.Log("Focus Crosshair In-active");
}
}
function NormalCrosshairExecute()
{
//Enable Normal Crosshair
NormalCrosshair.active = true;
//Wait for Seconds
yield WaitForSeconds (0.03);
//Disable Normal Crosshair
NormalCrosshair.active = false;
}
Answer by Jamora · Jul 27, 2013 at 02:56 AM
Have NormalCrosshairExecute execute only if the other crosshair is not shown.
if(!FocusCrosshair.active)
NormalCrosshairExecute();
Your answer
Follow this Question
Related Questions
spaceship aim 1 Answer
Dealing with multiple crosshairs 0 Answers
Simple GUI In game 1 Answer