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 /
This question was closed Jul 14, 2013 at 12:58 AM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by SpeedTutor · Jul 14, 2013 at 12:50 AM · javascriptguinothing

If "x" then do nothing?

This might be the most poorly designed script but is there anyway to stop the script from doing anything at a certain point? As I want to stop the script when health reaches the maximum value of 100.

 #pragma strict
      
 var tex1 : Texture;
 var tex2 : Texture;
 var tex3 : Texture;
 var tex4 : Texture;
 var health : float;
 private var enterCollider : boolean = false;
 
 //Damage collider
 function OnTriggerEnter (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         enterCollider = true; 
     }
 }
 
 //Normal state
 function OnTriggerExit (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         enterCollider = false; 
     }
 }
 
 function Start()
 {
     //Initial Health
     health = 100;
 }
 
 function Update()
 {
     //Health countdown whilst in damage collider
     if(health > 0  && enterCollider == true)
     {
     health -= Time.deltaTime;
     }
     
     //normal health regeneration
     if(health > 0 && enterCollider == false)
     {
     health += Time.deltaTime;
     }
     
     //When health reaches 100 again, do nothing?
     if(health == 100 && enterCollider = false)
     {
     //Do Nothing?
     }
 }
      
 function OnGUI() 
 {
     if (health <= 100)
     {
       GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex1);
       }
       
       if (health <= 90)
     {
       GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex2);
       }
       
       if (health <= 80)
     {
       GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex3);
       }
       
       if (health <= 70)
     {
       GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), tex4);
       }
 }
Comment
Add comment · Show 1
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 SpeedTutor · Jul 14, 2013 at 12:52 AM 0
Share

Ignore this post, I thought about it a little and found my own solution.

 //added
 var maxHealth
 
      if(health > maxHealth)
     {
     health = maxHealth;
     }

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

WorldToScreenPoint returns the same value when facing the opposite direction. 0 Answers

Creating a next and previous Tutorial 1 Answer

Lowering a variable 1 number lowering it entirely? 1 Answer

GuiTexture Width Change 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