Courentines / Delays,Learning courentine

Ill start off with my scripts-

    if (Input.GetMouseButtonDown(0))
    {
        if (guntimer <= 0)
        {
            shoot = true;
            guntimer = 10;
            print("Coroutine started");
            StartCoroutine(wait1());
            print("Coroutine ended");
            shoot = false;
        }
    }

IEnumerator wait1()
{
    yield return new WaitForSeconds(0.5);
}

essentially when the player clicks with the left mouse it changes the shoot boolean to true for 0.5 seconds, then switches back to false.

However, the ienumerator wait thing immediately ends, even with values such as 10.
what am i doing wrong?

P.s - Obviously new at unity, this is a school project.

“WaitForSeconds” waits only inside a coroutine. If you look at your program, your coroutine (wait1) does nothing. StartCoroutine, on the other hand, doesn’t wait. It starts the coroutine and continues immediately where it left off.

So, as you figured out, nothing happens.

What you want to do is to put the things that need to wait inside the coroutine as well.

This is an example of that (unrelated to your program)

public class Test : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Starting coroutine!");
        StartCoroutine(Wait());
        Debug.Log("Continuing immediately after coroutine!");
    }

    IEnumerator Wait()
    {
        Debug.Log("Starting wait...");
        yield return new WaitForSeconds(3);
        Debug.Log("Wait done!");

        // do your after-wait stuff here!
    }
}

This is the result:

Starting coroutine!
Starting wait...
Continuing immediately after coroutine!
Wait done!

so the coroutine appears to be working, however the script itself still doesnt seem to do anything.
I really did think it would fix the problem… so ill post it here instead.
If you find anything rather obvious i would be greatful if you could point it out.

using UnityEngine;
using System.Collections;

public class shootscript : MonoBehaviour {
public bool shoot = false;
public int guntimer = 0;
private Rigidbody rb;
public float speed;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

    // Counts down the guns timer, which tracks whether or not the gun was recently used.
    if (guntimer >= 0){
        guntimer = guntimer - 1;
    }

    // If left mouse clicked, if the player hasnt recently shot, shoot bool becomes true for 0.25 seconds.
    if (Input.GetMouseButtonDown(0))
    {
        if (guntimer <= 0)
        {
            shoot = true;
            guntimer = 50;
            print("Coroutine started");
            StartCoroutine(wait1());
        }
    }

    // This goes into a scoping position while right click is held. Not finished yet
    if (Input.GetMouseButtonDown(1))
    {
        // gameObject.transform.position = new Vector3(0f, 0f, 0f); Go into the scope position
    }
    else
    {
        // gameObject.transform.position = new Vector3(0f, 0f, 0f); Go to the normal position
    }

    if (shoot == true)
    {
        gameObject.SetActive(true);
    }
    else
    {
        gameObject.SetActive(false);
    }
    // This shows the object that represents the bullet / laser for a very short ammount of time. Graphical fx only.

}

void OnTriggerEnter(Collider other)
{
    if (shoot == true)
    {
        if (other.gameObject.CompareTag("Penguin"))
        {
            Destroy(other.gameObject);
        }
    }
}

IEnumerator wait1()
{
    yield return new WaitForSeconds(1f);
    print("Coroutine ended");
    shoot = false;
}

}

The script is attached to a transparent object that continues from the end of the players gun.