Quantcast
Channel: Answers for "Script for changing levels"
Viewing all articles
Browse latest Browse all 6

Answer by HJJ

$
0
0
Here's a script I got from unity-It works really well on almost and object that has a collider: ---------- using UnityEngine; using System.Collections; //extend MonoBehaviour so that we can attach this script to an object public class creditsload: MonoBehaviour { //A public bool so that we can change in the editor whether or not the button will quit the application public bool isQuit = false; //For the next three functions, the collider is absolutely necessary //these functions will not fire off if there is no collider //Fires off when the mouse hovers over the collider //When the mouse is over the item, change the colour of it to //red so that the player knows that it is interacting with it void OnMouseEnter() { renderer.material.color = Color.grey; } //Fires off when the mouse leaves the object //We want to change the colour of the object back to it's original when the mouse //is no longer over it so that is exactly what we do here void OnMouseExit() { renderer.material.color = Color.white; } //Fires off when the mouse is clicked while hovering over the object //Here we check if the bool was set to true or not and we load the level id not //or quit the application if true void OnMouseDown() { if(isQuit) { Application.Quit(); } else { Application.LoadLevel(7); } } } ---------- Now all you have to do is change the "MonoBehaviour" to the name you are calling the script. And if you already haven't done so, go to build settings and press add current. Then go down to the bottom where it says (7) and change it to the level number shown on you build settings. This should work.

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>