Okay, so, recently i made a script to enable an image when i hit it’s collider. The script’s function was to pause the game, and show the image. If the player pressed “P”, then the game would unpause and the image would not be there anymore.
So, as i am making a FPS game and i wanted to change my current combat system, i was thinking “why not?” so i kinda updated the script to to the following:
I wanted to make my script DISABLE a plane (that is a muzzleflash) when the player started the game, and then ENABLE when the player pressed the left mouse button, wait for let’s say 1 second and then disable it again. This would make a flash screen, and it would be easy to make.
But i am stuck! I don’t know what i did wrong, but it simply doesn’t do anything. It sucessfuly disable the plane in the start of the game, but it doesn’t enable and disable it like a flash when i press the left mouse button =(
Here’s the script (Java)
#pragma strict
var MuzzeFlash : GameObject; //The plane OR muzzeflash.
public var FireRate : float; //A variable to determine the time to wait before disabling it.
function Start () //This function will make the quad be disabled in the start of the scene.
{
MuzzeFlash.SetActive (false);
}
function CoUpdate(): IEnumerator //The only thing i could find that would fit was this.
{
if (Input.GetButton("Fire1")) { //On left mouse click:
MuzzeFlash.SetActive (true); //Enable the plane?
yield WaitForSeconds (FireRate); //Wait for the seconds in the variable.
MuzzeFlash.SetActive (false); //Disable the plane?
}
}