My collectable objects don't respond like they should after calling a coroutine for the first time?
I had been using unity for a while now, and currently i'm working on a recreation project of a web series with a few people, but i came across to an issue regarding my collectables.
my player and collectable disk scripts are written like this:
Player.cs
public class Player : MonoBehaviour
{
public CharacterController comp;
public AudioSource disk_sfx;
private AudioSource bkg_mus;
private float hor;
private float ver;
public float spd = 5.0f;
public bool ismove = true;
// Start is called before the first frame update
void Start()
{
bkg_mus = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if(ismove == false)
{
comp.Move(new Vector3(0, 0, 0));
StartCoroutine(delay_time());
}
else
{
movement();
}
}
private void movement()
{
hor = Input.GetAxis("Horizontal");
ver = Input.GetAxis("Vertical");
comp.Move(new Vector3(hor, 0, ver) * spd * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Disk")
{
ismove = false;
bkg_mus.Pause();
disk_sfx.Play();
}
}
public IEnumerator delay_time()
{
yield return new WaitForSeconds(5.0f);
disk_sfx.Stop();
bkg_mus.UnPause();
ismove = true;
}
}
diskobject.cs:
public class diskobject : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
//other.GetComponent<playercontrol>().disks++;
Destroy(gameObject);
}
}
}
My issue is that, after the player collects one object, it stops working well on the rest of the duplicated objects, when player collides with them they don't even react at all, and after that one object will get the function working, but only for a few seconds, i tried using a StopCoroutine() inside my delay_time() method, but that didn't work at all, is there a way to fix this?
here's my issue on video if you didn't understand what's my problem and what do i want to fix: https://streamable.com/bjefg4