Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by askri78 · Nov 02, 2015 at 03:42 PM · uibuttonevents

How to make a UI Button who opens a new level depending on a selected object?

I'm developping an architectural application in unity and i would like to create a unique Ui button that opens a specific level depending on the selected object (actually the objects are 2d plans of 9 appartments and each appartment have a unique corresponding level in wich player can do an interior walkthrough). I do not want to make a button for each appartment, neither click on one of the plans to directly access the corresponding level, but i would like to select one of the plans then click on the button to access the level corresponding to this plan. Can you help me please?

Thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fire_Cube · Nov 02, 2015 at 06:07 PM 1
Share

on each room you add a script that, on the button, change a variable to the name of the scene to load, and on the button, you just use Application.LoadLevel(levelName), with levelName the name of the level modified by the scripts on the rooms.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by askri78 · Nov 03, 2015 at 10:20 PM

Thanks for the answer. Ok so i've been able to make a script attached to the button that uses a variable to load the desired level. I also wrote the script that have to be attached to the selected object (actually the appartment 2d plan) in wich i declare the same public variable that will be used in the button script. Now the problem is i don't know how to communicate this variable between the to scripts. @Fire_Cube

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fire_Cube · Nov 04, 2015 at 11:45 AM 0
Share

you can use Gameobject.Find("theGameobjectThatContainTheButton").GetComponent().levelToLoad = the level to load;

with you're message, i understand you declare a variable with the level to load on each script, but i won't be the same var in the two. I'm not sure i have been clear, but i don't have much time now, i re write the answer in 3-4 hours

avatar image askri78 Fire_Cube · Nov 04, 2015 at 01:10 PM 0
Share

Thank you very much. It works now. Actually I used the script that keeps informations about the appartment (like area, orientation, etc) and added a public string variable wich is the reference for the appartment. This script is attached to each appartment gameobject and sends informations to the canvas. The canvas displays these informations as well as the level button when in game mode i click on one of the appartments. Now i attached a new script to this button wich gathers the appartment name variable from the canvas and loads the corresponding level (actually the level name of each appartment is the same as the appartment name string variable so the LevelLoad script uses the text information in the canvas to load the level).

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
     
     
 public class LevelLoad : $$anonymous$$onoBehaviour 
 {
 
     private string RefLot;
     private Transform LtoLoad;
     public Canvas InfoCanvas;
 
     public void LevelClick ()
 `` {
     LtoLoad = InfoCanvas.transform.Find("infoPanel/Haut/lot");
     RefLot = LtoLoad.GetComponent<Text>().text;
     Application.LoadLevel (RefLot);
     }
 
 }

I really don't know if there is a simplest way to reach the same result.

avatar image Fire_Cube askri78 · Nov 04, 2015 at 02:22 PM 0
Share

I don't see simplier way to do this :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Inherited CustomButton class is called on all scripts of type CustomButton with same Parent. 0 Answers

Button mouseover only works when other canvas is active 0 Answers

UI Jump Button - I want to click on the button to jump but instead I jump when I click anywhere on the screen. 0 Answers

Upgrade Weapon Stats on Different Script 0 Answers

Button AddListener - pass in a UnityAction 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges