2
\$\begingroup\$

I use timeline for creating an opening cutscene and I want to load the first level after the cutscene ends. So, I decided to use timeline signals. I created a signal emitter at the end of the cutscene and added LoadGamePlay script to the signal receiver component. The problem is that the function doesn't show up in the dropdown menu. I can just select "string name" and write the scene name in the inspector. But this doesn't help so level 1 cannot be loaded. I'm not sure what I'm doing wrong.

using UnityEngine;
using UnityEngine.SceneManagement;
 
public class LoadGamePlay : MonoBehaviour
{
   public string myScene = "";

   public void LoadLevel()
   {
      SceneManager.LoadScene(myScene);
   }
}

enter image description here

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Did you drag a script file into where it says LoadGamePlay, rather than a GameObject with an instance of the LoadGamePlay component attached to it? You won't be able to reference any instance methods (methods without static in their declaration) unless you have a reference to an instance of the component, not the script that defines the class. \$\endgroup\$
    – DMGregory
    Commented Jul 6, 2021 at 14:47
  • \$\begingroup\$ Yes! That was exactly the root of the problem. Thank you! I'll write this as an answer. \$\endgroup\$
    – Ali
    Commented Jul 7, 2021 at 10:22
  • \$\begingroup\$ @DMGregory I just have a quick question since it is related to this one. The level 1 scene loads very quickly (less than a second). So I wanted to ask do I need to add a loading screen in between? For sure I'll add more content to the first level so this way it might take longer but even in that situation, I think a loading screen (or a loading bar) would be pointless. \$\endgroup\$
    – Ali
    Commented Jul 7, 2021 at 10:42
  • \$\begingroup\$ It sounds like you've reasoned your way to your preferred answer there. \$\endgroup\$
    – DMGregory
    Commented Jul 7, 2021 at 11:13
  • \$\begingroup\$ Yes, my preferred answer is to not have a loading screen in there but wasn't sure so that was why I asked it. \$\endgroup\$
    – Ali
    Commented Jul 8, 2021 at 15:23

1 Answer 1

0
\$\begingroup\$

For solving this problem, I followed these steps:

  1. Created an empty obejct.
  2. Attached LoadGamePlay script to it as a component.
  3. Wrote the name of the scene I wanted to load. In this case, it was "Level 1".
  4. Dragged the game object into Signal Receiver in the inspector.
  5. In the drop down menu, selected LoadGamePlay and then LoadLevel().

Note: You can also drag the object into Signal Emitter's inspector field.

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .