- Home /
Load new scene on object click
I'm exploring other options but i'll also ask here.
I'm trying to set up a simple script so when a UI pointer on the FPS controller moves over objects, text comes up and if clicked a new scene is loaded. I tried a basic collider system where you enter the collider and click e, but it's imprecise and wasn't working.
Now i'm thinking a better option would be ray casting. So when the pointer moves over an item with a collider trigger and is clicked it will load the new scene. Problem is Ive never actually done ray casting and am having a really hard time coming up with a script to work here. It seems simple enough but I'm entry level C#. A lot of the previous answers to this question Ive found are outdated now.
So basically I just want a scrip so when the player goes up and looks at specific objects a text prompt comes up that says the objects name, and when you click it loads a new scene. I'm working on my C# but right now I'm floundering and rely heavily on help so if you can help I would greatly appreciate it.
Answer by DropoutGamer · Jul 17, 2019 at 11:38 AM
Try using raycast to detect that specific object https://docs.unity3d.com/ScriptReference/Physics.Raycast.html Confirm Detection using simple if condition , using object name or by using tag on object https://docs.unity3d.com/Manual/Tags.html if condition is true use a pop up that will get active using popupname.SetActive(True); use a button to load new/next scene SceneManager.LoadScene("SceneName"); Hopefully it will work.
Alright this was actually helpful in trying to figure out what all to do, but I'm not 100% sure where to start with the script or how to put it all together into a working one. Again I'm pretty entry C#. I mostly do sculpting modeling texturing and level design so scripting is still an area where I'm lacking.
Your answer
Follow this Question
Related Questions
Raycasting working in editor, but not in build 0 Answers
Animation/Scripting 1 Answer
how to load a previous scene after a "restart" scene? 2 Answers
Getting the rotation of raycast target object and applying to the player (noob question) 1 Answer
GetSceneByPath fails after LoadScene (Async or not) - Unity 5.5.2 0 Answers