Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by spiralfire11 · Dec 09, 2013 at 09:05 PM · pausehealthbar

Manabar Pause Limit

I"m trying to get that the player can no longer pause when the ManaBar is empty. But I just can't seem to get a script in my mind for it... Here's the Pausing script:

 using UnityEngine;
 using System.Collections;
 
 public class Freeze : MonoBehaviour {
     public int p = 0;
     private GameObject target;
     public void Start() {
     target = GameObject.FindGameObjectWithTag("player");     
 }
     public void Update () {
     AddjustCurrentfreeze(0);
     }
     public void AddjustCurrentfreeze(int adj) {
         p += adj;
         
     if (Input.GetKeyDown(KeyCode.P))
     {
     if (p == 0)
     {
     Time.timeScale=0;
     Screen.showCursor = true;
     Screen.lockCursor = false;            
     p = 1;
     PlayerManaBar eh = (PlayerManaBar)target.GetComponent("PlayerManaBar");
     eh.AddjustCurrentMana(-100);    
     }
     else
     {
     Time.timeScale=1.0f;
     p=0;
   
     }
     }
 
 }
 }

Here's the ManaBar script :

  using UnityEngine;
     using System.Collections;
      
     public class PlayerManaBar : MonoBehaviour {
      public GameObject target;
     GUIStyle style = new GUIStyle();
     Texture2D texture;
     Color yeColor = Color.yellow;
     Color cyanColor = Color.cyan;
     private int curMana = 1000;
     private int maxMana = 1000; 
     void Start()
     {
     texture = new Texture2D(1, 1);
     texture.SetPixel(1, 1, cyanColor);
     }
      
    void Update()
     {
         AddjustCurrentMana(0);
     }
     public void AddjustCurrentMana(int adj) {
         curMana += adj;
             
     if(curMana < 0)
     {     
     curMana = 0;
     }
     
     if(curMana > maxMana)
     {
     curMana = maxMana;
     }
         
     if(maxMana < 1)
     {
     maxMana = 1;
     }
 if (curMana <= 1000)
 {
 texture.SetPixel(1, 1, cyanColor);
 }
 
     }
  
 public void OnGUI()
 {
  
 texture.Apply();
  
 style.normal.background = texture;
     GUI.Box(new Rect(10, 40, curMana, 20), new GUIContent(""), style);
     GUI.Box(new Rect(10, 40, 1000, 20), "");    
     
 }
 }
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
0
Best Answer

Answer by spiralfire11 · Dec 12, 2013 at 02:06 AM

Dont' worry I fixed myself:

  using UnityEngine;
     using System.Collections;
      
     public class PlayerManaBar : MonoBehaviour {
      public GameObject target;
     GUIStyle style = new GUIStyle();
     Texture2D texture;
     Color yeColor = Color.yellow;
     Color cyanColor = Color.cyan;
     public int curMana = 1000;
     private int maxMana = 1000; 
     void Start()
     {
     texture = new Texture2D(1, 1);
     texture.SetPixel(1, 1, cyanColor);
     }
      
    void Update()
     {
         AddjustCurrentMana(0);
     }
     public void AddjustCurrentMana(int adj) {
         curMana += adj;
             
     if(curMana < 0)
     {     
     curMana = 0;
     }
     
     if(curMana > maxMana)
     {
     curMana = maxMana;
     }
         
     if(maxMana < 1)
     {
     maxMana = 1;
     }
 if (curMana <= 1000)
 {
 texture.SetPixel(1, 1, cyanColor);
 }
         

 **if (curMana <= 0) {
                 Freeze eh = (Freeze)target.GetComponent("Freeze");
                 eh.AddjustCurrentfreeze(1);**

                 }
     }
  
 public void OnGUI()
 {
  
 texture.Apply();
  
 style.normal.background = texture;
     GUI.Box(new Rect(10, 40, curMana, 20), new GUIContent(""), style);
     GUI.Box(new Rect(10, 40, 1000, 20), "");    
     
 }
 }

Then I selected my target as my main character

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

Answer by foobuggy · Dec 09, 2013 at 11:00 PM

Just slightly modifying your current scripts - how about adding a public variable to PlayerManaBar like this:

 public int mana{ get{ return curMana; }}

then in your Freeze script get the PlayerManaBar component before you check for the "P" keypress and just modify your "if" statement to be something like:

 PlayerManaBar eh = (PlayerManaBar)target.GetComponent("PlayerManaBar");
 if(p == 0 && eh.mana > 0){ ... do stuff ... }
Comment
Add comment · Show 1 · 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 spiralfire11 · Dec 12, 2013 at 01:35 AM 0
Share

its supposed to be if (cur$$anonymous$$ana == 0) { p=0; }

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

17 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

Related Questions

Pause menu... Isn't pausing everything... 1 Answer

How to save players position then load a level (pause menu) 2 Answers

pause the audiolistener of the main camera doesn't stop it from generating sound 0 Answers

A trigged pause menu 1 Answer

Time.timeScale seems doesn't work with Update 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