Hello guys I wrote a script but I have a problem I get the error Assets / MuzzleFlash.cs (18,32):

public class MuzzleFlash : MonoBehaviour
{
public GameObject flash;

void Update()
{
if (Input.GetMouseButton(0))
{

IEnumerator MyMethod()
{
flash.SetActive(true);

yield return new WaitForSeconds(2);

flash.SetActive(false);
}

}

{

}

}

}

Hi,
You can start your Coroutine like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MuzzleFlash : MonoBehaviour
{
    public GameObject flash;

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            StartCoroutine("MyMethod");
        }
    }
    IEnumerator MyMethod()
    {
        flash.SetActive(true);
        yield return new WaitForSeconds(2);

        flash.SetActive(false);
    }
}

Please use forum tools to post pieces of code next time.

1 Like

Thanks man you saved my day sorry

this is my first post next time I’ll be careful what you say