Problem z c# w unity

0

witam, mam pewien problem z moim kodem w unity, podaje pod spodem kod oraz jaki błąd mi wyskakuje po próbie kompilacji, wie ktoś jak to naprawić?

Błąd:

Treść „Pistol.Reload()” nie może być blokiem iteratora, ponieważ „void” nie jest typem interfejsu iteratora
Kod:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class Pistol : MonoBehaviour
{

    public Sprite idlePistol;
    public Sprite shotPistol;
    public float pistolDamage;
    public float pistolRange;
    public AudioClip shotSound;
    public AudioClip reloadIntroSound;
    public AudioClip emptyGunSound;
    public AudioClip oneReloadSound;
    public AudioClip outroRealoadSound;

    public Text ammoText;

    public int ammoAmount;
    public int ammoClipSize;

    public GameObject bulletHole;

    int ammoLeft;
    int ammoClipLeft;

    bool isShot;
    bool isReloading;

    AudioSource source;


    void Awake()
    {
        source = GetComponent<AudioSource>();
        ammoLeft = ammoAmount;
        ammoClipLeft = ammoClipSize;
    }

    void Update()
    {
        ammoText.text = " " + ammoClipLeft + "\n" + ammoLeft;

        if (Input.GetButtonDown("Fire1") && isReloading == false)
            isShot = true;
        if (Input.GetKeyDown(KeyCode.R) && isReloading == false)
        {
            Reload();
        }
    }

    void FixedUpdate()
    {
       
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (isShot == true && ammoClipLeft > 0 && isReloading == false)
        {
            isShot = false;
            ammoClipLeft--;
            source.PlayOneShot(shotSound);
            StartCoroutine("shot");
            
            
            if (Physics.Raycast(ray, out hit, pistolRange))
            {
                Debug.Log("Wszedlem w kolizje z " + hit.collider.gameObject.name);
                
                hit.collider.gameObject.SendMessage("pistolHit", pistolDamage, SendMessageOptions.DontRequireReceiver);
                
                Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
            }
        }
        else if (isShot == true && ammoClipLeft <= 0 && isReloading == false)
        {
            
            isShot = false;
            Reload();
        }
    }

    void Reload()
    {

        int bulletsToReload = ammoClipSize - ammoClipLeft;
        if (ammoLeft >= bulletsToReload)
        {
            isReloading = true;
            StartCoroutine("ReloadWeapon");
            source.PlayOneShot(reloadIntroSound);
            yield return new WaitForSeconds(0.5f);
            do
            {

                ammoLeft--;
                ammoClipLeft++;
                source.PlayOneShot(oneReloadSound);
                yield return new WaitForSeconds(0.25f);

            }
            while (ammoClipLeft == 5 || ammoLeft == 0);
            source.PlayOneShot(outroRealoadSound);
            isReloading = false;

        }
        else if (ammoLeft <= 0)
        {
            source.PlayOneShot(emptyGunSound);
        }
    }

    IEnumerator Shot()
    {
        GetComponent<SpriteRenderer>().sprite = shotPistol;
        yield return new WaitForSeconds(0.1f);
        GetComponent<SpriteRenderer>().sprite = idlePistol;
    }

}
0

błąd jest w innym kawałku kodu

0
abrakadaber napisał(a):

błąd jest w innym kawałku kodu
podałem cały skrypt od broni :p

0

yield return zwraca typ od IEnumerator<T>

Tu masz przykład użycia.
https://docs.unity3d.com/ScriptReference/WaitForSeconds.html

0

to wszystko tłumaczy :p, dzięki wieeelkie, polecam tego forumowicza (nie umiem zamknąć tematu help)

1 użytkowników online, w tym zalogowanych: 0, gości: 1