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 sirofjava · Oct 07, 2017 at 07:30 PM · unlock

Level Unlock system

Hi all

kindly i need your support in my Unlock level system , i finlized the following steps :

first i built the UI as the following screen shoot : alt text

then i use the LevelSelector script and its working fine as the followin screen shoot : alt text

the LevelSelector script syntax code as the following :

using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class LevelSelector : MonoBehaviour {

 //public SceneFader fader;

 public Button[] levelButtons;

 void Start ()
 {
     int levelReached = PlayerPrefs.GetInt("levelReached", 1);

     for (int i = 0; i < levelButtons.Length; i++)
     {
         if (i + 1 > levelReached)
             levelButtons[i].interactable = false;
     }
 }

 public void changeToScene(int changeTheScene)
 {
     SceneManager.LoadScene(changeTheScene);
 }

}

then i used the enemy health manager as the following :

using UnityEngine; using System.Collections;

public class EnemyHealth :MonoBehaviour {

 public float curHealth;
 public float maxHealth;
 
 
 void Start () {
     
     curHealth=100f;
     maxHealth =100f;
     
 }
 
 void Update () {
     EHealthManager (0);
 }
 
 
 public    float EHealthManager(float f){
     
     if (curHealth > maxHealth)
         curHealth = maxHealth;
     
     if (curHealth < 0)
         curHealth = 0 ;
     
     if (maxHealth < 1)
         maxHealth = 1;
     curHealth += f;


     float modifiedHealth  = (curHealth / maxHealth) * 500;
     return modifiedHealth;

 }
 
 void OnGUI(){
     
     GUI.Box(new Rect(20,50,EHealthManager(0),25), ((int) curHealth).ToString() + "/" + ((int)maxHealth).ToString());
     
 }

}

then i use LevelManager script to unlock the next level "button2" as the following :

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour { public string nextLevel = "Level-2"; public int levelToUnlock = 2; public GameObject EnemyHealth;

 public void LoadNextLevel()
 {


     if(EnemyHealth.GetComponent<EnemyHealth>().curHealth /EnemyHealth.GetComponent<EnemyHealth>().maxHealth <= 0){
         

     int currentUnlock = PlayerPrefs.GetInt("levelReached");

     if (currentUnlock < levelToUnlock) {
         PlayerPrefs.SetInt("levelReached", levelToUnlock);
     }
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
         PlayerPrefs.SetInt("SavedLevel1", 1);
         Debug.Log("SavedLeve1 = 1");

 

}

 }

}

my issues :

I need ( level manager script) doing the following : 1. If the player health less than zero restart the game that mean he lose to win 2. If the total enemy’s health less than zero , message you win then load next level 3. If the total enemy’s health less than zero unlock button level 2 4. Save all level status 5. how to restart the unlock system

appricated your kindy support to fix level manager script where i dont face any error but its not working ,

level.jpg (10.8 kB)
level-selector.jpg (18.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to open a gate with a key ? 1 Answer

How to make PlayerPrefs delete if the player didn't touch game finish collider 1 Answer

Serial key before my game starts 1 Answer

Purchase Level Unlock System 1 Answer

When dragging a Door open using RIGIDBODYSCRIPT Plays sound. 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