Change level after selecting a number of buttons
Hi,
I am new in unity and i would really need some help with something i m stuck in.
I have 28 buttons and i want after i select 16 of them ( 16 random selectiions) to change the scene.
Please give me guidance in this.
Thank you in advance.
I tried to use this code
#pragma strict var level=""; function Start () { } function Update () { print(GameObject.FindGameObjectsWithTag("Player").Length); if(GameObject.FindGameObjectsWithTag("Player").Length>16) {Application.LoadLevel(level);} }
to count or that i wanted to do, but it doesn t work. i tagged all the buttons with the name "Player" but because i have 28 and the value in the code is if>16 will change the scene.
As i said above i need the code somehow to count 16 random selections and after that to change the screen please could you give me some help.
Answer by Prasenjit_LinuxGuy · May 12, 2016 at 03:47 PM
Have you added counter in your game? If not , make counters first
Please could you guide me in this.
As i said i'm new at this.
Thank you.
Hi again i tried to use this code
#pragma strict var level=""; function Start () { } function Update () { print(GameObject.FindGameObjectsWithTag("Player").Length); if(GameObject.FindGameObjectsWithTag("Player").Length>16) {Application.LoadLevel(level);} }
to count or that i wanted to do, but it doesn t work. i tagged all the buttons with the name "Player" but because i have 28 and the value in the code is if>16 will change the scene.
As i said above i need the code somehow to count 16 random selections and after that to change the screen please could you give me some help.
I managed to add a counter for buttons using this script
using UnityEngine;
using System.Collections;
public class Counter : $$anonymous$$onoBehaviour {
int counter=0;
void OnGUI()
{
GUI.Label (new Rect (40, 20, 200, 50), "COUNTER: " + counter); {
}
}
void Update() {
if (Input.Get$$anonymous$$ouseButtonDown(0))
counter ++;
}
}
Now could you helped me making it when it reaches 16 to change the scene?
Answer by sam_irfan · May 13, 2016 at 10:46 AM
I've managed to do what i wanted now i just need to limit the times you are allowed to click the buttons. But this is the code.
using UnityEngine;
using System.Collections;
public class Counter : MonoBehaviour {
int counter=0;
void OnGUI()
{
GUI.Label (new Rect (40, 20, 200, 50), "COUNTER: " + counter); {
if (counter >= 16) {
Application.LoadLevel("win_scene");
}
}
}
void Update() {
if (Input.GetMouseButtonDown(0))
counter ++;
}
}