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 /
avatar image
-1
Question by BlastOffProductions · Jun 02, 2016 at 04:05 PM · iosbuttontouchrandomlevel load

How to load a random level when button is touched?

Okay, I have seen many answers for this question, but none seem to work. I need a way to randomly select a level between two levels, when a button is touched. I am not very good at making scripts. And iv'e tried many scripts, but none work at all. Does anyone know anything about this?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aWolfKing · Jun 02, 2016 at 04:30 PM

You can load scenes by their number or name.

 int[] numbers = {0,1}; //possible random numbers 
 string[] scenenames = {"scene1", scene2}; //scene names in order of numbers //0 = scene1, 1 = scene2
          
 SceneManager.LoadScene( scenenames[Random.Range(0,numbers.lenght)] ); //place this inside void










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 BlastOffProductions · Jun 02, 2016 at 05:41 PM -1
Share

Thanks for answering : ) Though for some reason when I use this script it gives me this error: Assets/RandomLevelHe2.cs(15,17): error CS0103: The name `Scene$$anonymous$$anager' does not exist in the current context.

avatar image Hellium BlastOffProductions · Jun 03, 2016 at 09:46 AM 1
Share

How about making research in the manual ??

Just import the UnityEngine.Scene$$anonymous$$anagement namespace

avatar image BlastOffProductions Hellium · Jun 03, 2016 at 05:26 PM 0
Share

Sorry, very new to this. Very, very new!

avatar image
0

Answer by BlastOffProductions · Jun 03, 2016 at 12:31 PM

Here is the current script I have: using UnityEngine; using System.Collections;

public class RandomLevelHe2 : MonoBehaviour { public Object He2; public Object TapTest;

 // Use this for initialization
 void Start () {

 }

 // Update is called once per frame
 void Update () {if ((Input.touchCount == 1) &&
     (Input.GetTouch(1).phase == TouchPhase.Began) ){
         Application.LoadLevel ("He2");
         Application.LoadLevel ("TapTest");


     }

 }

}

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 BlastOffProductions · Jun 04, 2016 at 05:38 PM 0
Share

Anyone????

avatar image Hellium · Jun 04, 2016 at 05:56 PM 1
Share
 (Input.GetTouch(1).phase == TouchPhase.Began) ){
         if( Random.value > 0.5f )
               Application.LoadLevel ("He2");
          else
                 Application.LoadLevel ("TapTest");
      }

avatar image BlastOffProductions Hellium · Jun 06, 2016 at 04:10 AM 0
Share

Thanks! A lot! God Bless!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I swipe function that lets the player select buttons? 0 Answers

Help with touch input for iOS please! 1 Answer

Is touch began guaranteed? 0 Answers

Multi touch not working - What's wrong with this code? 1 Answer

Raycast issue ... 1 Answer


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