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

Loading levels in order from build settings through function, also, in new Unity build why is sound

Discussion in 'Scripting' started by TonyNowak, Jul 19, 2017.

  1. TonyNowak

    TonyNowak

    Joined:
    May 10, 2010
    Posts:
    316
    1. So here is my code for a game object that is too be destroyed when ran over, but I wanted to play a sound, i first tried through the game manager to have the audio play through the general source when contact was mode, that threw an error. So I tried cheaply doing it directly to the object, and too my suprise, the same thing: https://hastebin.com/egipuripex.cs

    I recently updated to Unity 2017.1 after a long period of neglecting updates, and i find a lot of things that should work aren't, I've look at the documentation and various forums but i still can't figure this out, it keeps throwing: Type `UnityEngine.Component' does not contain a definition for `Play' and no extension method `Play' of type, no matter how o structure it or which different things I try. :/

    2. In Unity 2017, is there any way to lets say have a function, I have one called Nextlevel, after the parameters are met and NextLevel is called, is there a way to write something outside of implicitly saying which level to go too, like it automatically goes to the next level in build order, this would be super helpful for something I'm currently doing.

    I appreciate whatever assistance you can give me, and I appreciate you guys taking the time to too look at this.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Did what thing? You haven't told us the error. You've pasted your code into hastebin for some reason instead of just inserting it here, but it looks OK to me — without more detail about what you want or what went wrong, how can we help?

    Not this code, it doesn't. You don't have any calls to Play in this code. If you're referring to the commented-out code, well that's calling Play on an AudioSource, which should work just fine (see the docs).

    If you show us the actual code that generates an error, along with the actual error generated, I'm sure we can help.

    You could use SceneManager.LoadScene with an index, as shown in the build dialog. (And you could use SceneManager.GetActiveScene().buildIndex to get the index of the current scene, if you don't have any better way to track that.)
     
  3. TonyNowak

    TonyNowak

    Joined:
    May 10, 2010
    Posts:
    316
    I have fixed it (forgot namespace, been a long day), I seemed to have forgotten why I stopped posting here on this forum. Very condescending.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I was trying to be helpful — I'm sorry it came off otherwise. But, I'm glad you fixed the problem!