Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Coroutine stops executing if raycast function returns true?

Discussion in 'Scripting' started by Clydey2Times, Jan 6, 2020.

  1. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    I'm having a strange problem with my weapon script. I use a coroutine to handle shooting, and I execute a raycast function within the coroutine. However, my coroutine only executes the lines after the raycast function of said function returns false.

    Can someone shed some light on what I'm missing? Is there a problem with my logic? Have I misunderstood something about how coroutines work?

    Edit: Figured out the issue. I'm not sure how to delete the thread. I hadn't assigned some references, but the errors weren't showing up in the console.
     
    Last edited: Jan 6, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Generally we don't want threads deleted. Every bit of accumulated knowledge may help someone. The mods usually only delete when it's completely off-topic, and in this case it's nice that you solved your issue and came back and gave us the tl;dr of what went wrong and how you fixed it! Somebody might benefit from that in the future!
     
  3. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    Ah, I see. Thanks for letting me know.