- Home /
How to make a gameobject take you to a scene when clicked?
I am making a game and made a main menu and some scenes. I'm trying to implement it so when you click on the gameobject (In my case a rectangle) it will take you to the level that you define. Any help? Thanks
I made a script that will let me do what I asked above now!
Answer by Froggerdog · Jan 11, 2014 at 05:52 AM
make an if then statement that when mousebutton is released it does Application.LoadLevel (1) or whatever. you add scenes under file > build settings and it tells you which number it is, then type that number in. here is an example of how I made public variables and dropped each menu item into them inside the inspector to use them.
- var isExit=false; var isPlay=false; var isCredit=false; public var Creator : GameObject; public var Asset : GameObject; public var Will : GameObject; public var Unity : GameObject; - function OnMouseEnter() { renderer.material.color=Color.gray; } function OnMouseExit() { renderer.material.color=Color.white; } function OnMouseUp(){ if (isExit==true) { audio.Play(); Creator.active=false; Asset.active=false; Will.active=false; Unity.active=false; yield WaitForSeconds (1); Application.Quit(); } if (isPlay==true) { audio.Play(); Creator.active=false; Asset.active=false; Will.active=false; Unity.active=false; yield WaitForSeconds (1); Application.LoadLevel(1); } if (isCredit==true) { audio.Play(); Creator.active=true; Asset.active=true; Will.active=true; Unity.active=true; } }
this also has code for making the text turn grey when hovered over, playing a clicking sound when clicked, and activating more text if the credits text is selected. hope this helped at all.
Hi I tried your script and it didnt work because of compiler errors.
Answer by NutellaDaddy · Jan 11, 2014 at 05:52 AM
Make sure to make isTriangle true when you start the scene and attach the object to the triangle.
using UnityEngine; using System.Collections;
 public class LoadLevel : Monobehavior 
 {
       public bool isTriangle;
       void OnMouseDown()
        {
          if(isTriangle = true)
          {
            Application.LoadLevel("LevelName");
          }
        }
 }
Answer by dyarbrough93 · Jan 11, 2014 at 05:51 AM
C#:
  void OnMouseDown() {
       Application.LoadLevel ("SceneName");
     }
Your answer
 
 
             Follow this Question
Related Questions
How to save/load references to components and prefabs 1 Answer
Find object by tag after LoadLevel 2 Answers
GameObjects load problem 1 Answer
Does the Singleton GameObject need to be in all scenes where i need to access it? 2 Answers
My Tags are getting changed, when its loaded from Asset Bundle. 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                