public GameObject laser;
public Transform spawnPoint;
private float Cooldown = 5f;
private float cooldownTime = 5f;
private bool spawned;
private GameObject laserbeam;
private void Start()
{
Cooldown = cooldownTime;
}
// Update is called once per frame
void Update()
{
if (!spawned)
{
Cooldown -= Time.deltaTime;
}
if (Cooldown <= 0)
{
laserbeam = Instantiate(laser, spawnPoint.position, Quaternion.identity) as GameObject;
Cooldown = cooldownTime;
if (!spawned)
{
Cooldown -= Time.deltaTime;
spawned = true;
}
}
if (spawned)
{
Destroy(laserbeam);
}
}
}
this the code and i need to fix the idea is i am trying to spawn a laserbeam the destroying after an amount of time the istantiating it like a obstacle