I need help at my reload function

Hey guys,
I have got a problem at my reload function.
I am trying to start a timer after the button “r” is pressed. This timer should be 5 seconds long.
I don’t get the problem.

Here is my script.

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

public class shoot : MonoBehaviour
{
public float offset;
public bool full = true;
public int ammo = 30;

public GameObject projectille;
public Transform shotPoint;

private float timeBtwShots;
public float startTimeBtwShots;

void Update()

{
if (full == true)
{
if (Input.GetMouseButtonDown(0))
{

Instantiate(projectille, shotPoint.position, transform.rotation);
timeBtwShots = startTimeBtwShots;
ammo–;
}
}

if (ammo == 0)
{
full = false;
}

if (Input.GetButtonDown(“reload”))
{
StartCoroutine(StartTimer(50));
}
}

IEnumerator StartTimer(float timeLeft) //This StartTimer is the problem
{
Reload();
}

void Reload()
{
ammo = 30;
}
}

Please use the code tags when posting code: Using code tags properly

This should point you in the right direction: Unity - Scripting API: WaitForSeconds

Thanks a lot.
I got it. Now it works

1 Like