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 Eneira · Jul 09, 2016 at 02:39 PM · script.

lvl win & lvl lose windows

Hello! Ive stuck with problem to write a code for "LevelWinWindow" & "LevelLoseWindow". Now Im in process about lvllosewindow. And i dont know how create logic that i need. Should appear window with "lose" after char dies, and "win" when he got 100 kills. code for "lose" looks like this: Script HUD.

 public class HUD : MonoBehaviour {
 
     [SerializeField]
     public GameObject loseWindow;
 
     //private GameObject LevelLoseWindow;
 
     public void ShowWindow(GameObject loseWindow)
     {
         loseWindow.SetActive(true);
         //ControlCH.Instance.State = GameState.Pause;
     }
 
     public void ShowLevelLoseWindow()
     {
        // loseWindow.alpha = 1.0f;
         ShowWindow(loseWindow);
     }
 
 
     static private HUD _instance;
 
     public static HUD Instance
     {
         get
         {
             return _instance;
         }
     }
     private void Awake()
     {
         _instance = this;
     }
 
     public void ButtonRestart()
     {
 
     }
 
     
 }

And script for Character:

  public void GameOver()
     {
         HUD.Instance.ShowLevelLoseWindow();
     }
 
 
 
  public void Destroyed()
     {
             GameOver();
         
         //SceneManager.LoadScene(SceneManager.GetActiveScene().name);
     }

Any ideas ? plz =(

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Petch12 · Jul 09, 2016 at 08:05 PM

OK, for the char when dead. You want to firstly check the gameObject (char) is not active then if the gameObject (char) is not active show the Lose window (in the char script):

  void Lose()
         {
             if (!gameObject.activeSelf)
             {
                 //show Lose window
             }
         }

Second, in order to check whether the char has won you are going to need an int which stores the number of kills.:

 void Update()
     {
         if (numOfKills == 100)
         {
             won();
         } 
     }
 
     void won()
     {
         //all you need is to show win.
     }

Although you will need to increase the number of kills everytime your char kills an enemy.

I hope this is what you meant, if not just say and I'll get back to you.

Comment
Add comment · Show 9 · 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 Eneira · Jul 10, 2016 at 05:45 PM 0
Share

Thank you, i will try it and then answer you about my result. P.S. my script about score looks like that :

 using UnityEngine.UI;
 using UnityEngine;
 using System.Collections;
 
 public class ScoreLabel : $$anonymous$$onoBehaviour {
     public static int score;
     
     private Text label;
         
         
     // Use this for initialization
     void Start ()
     {
         label = gameObject.GetComponent<Text>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         label.text = score.ToString();
     }
 }

avatar image Petch12 Eneira · Jul 11, 2016 at 04:02 PM 0
Share

No problem, hope it works for you. (by the way the scripts I attached won't directly copy into your game as they weren't built for it - they are meant only to help you along (and I hope they do!) :). Any other problems just reply

avatar image Eneira Petch12 · Jul 11, 2016 at 07:29 PM 0
Share

Unfortunately, i don't know what is wrong, logic seems to me normal but it doesn't work ... thats why i think that problem is not in code but maybe in editor... phhhhh i'm losing my motivation =(

Show more comments
Show more comments
avatar image Petch12 Eneira · Jul 13, 2016 at 11:51 AM 0
Share

Ok sorry my last question about text was bad. (sorry ;) . Is it only 'LoseWindow' that isn't working???

If this is the case I would just create LoseWindow (within canvas - not from prefab) and then just set it active when needed. (I personally don't use SerializeField very often (if at all xD - I probably should though http://forum.unity3d.com/threads/do-you-use-serializefield-a-lot.307079/) so I would use the method I described). So. If LoseWindow needs some text and also a panel (ui elements), attach both text and panel to a GameObject (LoseWindow - default NOT set active) and then when needed (when player dies) set LoseWindow active.

avatar image Eneira Petch12 · Jul 13, 2016 at 06:21 PM 0
Share

What should i do with that ? ...

 public class HUD : $$anonymous$$onoBehaviour {
 
     
     public GameObject loseWindow;
 
     public void ShowWindow(GameObject loseWindow)
     {
         loseWindow.SetActive(true);
         //ControlCH.Instance.State = GameState.Pause;
     }
 
     public void ShowLevelLoseWindow()
     {
       
         ShowWindow(loseWindow);
     }
 
 
     static private HUD _instance;
 
     public static HUD Instance
     {
         get
         {
             return _instance;
         }
     }
     private void Awake()
     {
         _instance = this;
     }
 
     public void ButtonRestart()
     {
 
     }
 
     
 }

Because when I'm trying to access ShowLevelLoseWindow() method in method Die() of character script - it is not working =( ...

avatar image Petch12 Eneira · Jul 13, 2016 at 08:55 PM 0
Share

I see. The problem is that you are trying to access a variable from a HUD(script) in PlayerScript (right??)

If this is what you are wanting to do ([Check this][1])

you are going to want something like:

         GameObject HUD = GameObject.Find("////"); //the gameobject HUD script is attached to//
 
         HUDScript hudscript= HUD.GetComponent<//NameOfScript - I believe "HUD">();
         hudscript.LoseWindow.SetActive(true);

something like this. [1]: http://answers.unity3d.com/questions/42843/referencing-non-static-variables-from-another-scri.html

avatar image Eneira Petch12 · Jul 14, 2016 at 06:12 PM 0
Share

No = (I don't think that it is a problem, because that's why I did "HUD _instance" in the script - to access anything from it and any another script. See example(That was already mentioned). The problem is that "it" can't see what to get and where its place to... That is a problem.

  public void GameOver()
      {
          HUD.Instance.ShowLevelLoseWindow();
      }
  
  
  
   public void Destroyed()
      {
              GameOver();
          
          //Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);
      }

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

How can i set transform.position on y ? And why i'm getting error cannot convert double to float ? 3 Answers

Displaying score from a scene to another 2 Answers

How would i make it transform player.position =target.position? 2 Answers

How can i rename a bool variable in inspector according to false/true mode ? 1 Answer

How can i slow down object rotation when releasing the mouse button and speed up when pressing the button again ? 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