Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Level/Scene Switcher/changer buttons , for android

Discussion in '2D' started by Athos-Krul, Aug 31, 2014.

  1. Athos-Krul

    Athos-Krul

    Joined:
    Aug 12, 2014
    Posts:
    22
    I made some scene for a 2d game using sprites. So in my MainMenu Scene i want to have 2 or more sprite buttons, so when i click on them a specific level is loaded.

    I used this code( for 2 levels), but when i touch the screen it loads just first scene( Level1).I don't know how to make it response to the touch just when i hit the sprite button but not the hole screen.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. function Update () {
    4.     if(Input.GetMouseButton(0))
    5.         Application.LoadLevel("Level1");
    6.     }
     
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    I am bit confused regarding your problem whether its related to the LoadLevel or the click on the screen.
    However its loading the first level only all the time because you have hard coded the value "Level 1" in the Application.LoadLevel.

    Secondly if you dont want the touch to be simulated on the whole sreen then you need to remove the current listener of the event in the Update function. Just add the collider over the button and listen to the OnMouseDown method.

    Hope this helps!
     
  3. Athos-Krul

    Athos-Krul

    Joined:
    Aug 12, 2014
    Posts:
    22
    Code (CSharp):
    1. using UnityEngine;
    2.     using System.Collections;
    3.    
    4.     public class L1 : MonoBehaviour {
    5.         void OnMouseDown() {
    6.             Application.LoadLevel("MainScene");
    7.         }
    8.     }
    thanks, it worked

    P.S. actually they are both the resoults of one problem