I have a gameobject that’s supposed to be instantiated and destroyed quickly. Problem is, Instead of being instantiated once, my gameobject is being instantiated multiple times. So I decided to limit it with a boolean. Problem is that I get an error… see for yourself:
using UnityEngine;
using System.Collections;
public class ActivateEffect : MonoBehaviour {
public GameObject LightningPrefab;
public GameObject instance;
private bool InstantiateOnce;
// Use this for initialization
void Start () {
InstantiateOnce = false;
}
void FixedUpdate ()
{
if (Input.GetKeyDown(KeyCode.L) && InstantiateOnce == false) {
var instance = (GameObject)Instantiate (LightningPrefab, transform.position, LightningPrefab.transform.rotation);
InstantiateOnce = true;
Destroy (instance, 0.5f);
}
if (instance == null)
{
InstantiateOnce = false;
}
}
}
Assets/CustomModels/ActivateEffect.cs(21,21): error CS0135: `instance’ conflicts with a declaration in a child block