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 /
  • Help Room /
avatar image
0
Question by klovaaxel1000 · Nov 09, 2015 at 11:09 AM · script.

What is wrong with my script

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class HealthBar : MonoBehaviour {

 public RectTransform healthTransform;
 private float cachedY;
 private float minXvalue;
 private float maxXValue;
 private int currentHealth;

 private int CurrentHealth
 {
     get{ return currentHealth;}
     set
     { 
         currentHealth = value;
         HandleHealth();
     }

 }

 public int MaxHealth;
 public Text healthText;
 public Image visualHealth;
 public float coolDown;
 private bool onCD;


 // Use this for initialization
 void Start () 
 {
     cachedY = healthTransform.position.y;
     maxXValue = healthTransform.position.x;
     minXvalue = healthTransform.position.x - healthTransform.rect.width;
     currentHealth = MaxHealth;
     onCD = false;
 }

 IEnumerator coolDownDmg()
 {
     onCD = true;
     yield return new WaitForSeconds (coolDown);
     onCD = false;
 }
 
 // Update is called once per frame
 void Update () {
 
     HandleHealth();
 }

 private void HandleHealth()
 {
     healthText.text = "Health: " + currentHealth;

     float currentXValue = MapValues(currentHealth, 0, MaxHealth, minXvalue, maxXValue)

         //ERROR HERE //ERROR = Unexpected symbol `healthTransform'
         healthTransform.localPosition = new Vector3(currentXValue, chachedY); 

     if(currentHealth > MaxHealth/2)//More than 50%
     {
         visualHealth.color = new Color32((byte)MapValues(currentHealth, MaxHealth/2, MaxHealth, 255, 0),255,0,255);
     }
     else//Less than 50%
     {
         visualHealth.color = new Color32(255, MapValues(currentHealth,0,MaxHealth/2,0,255),0,255);
     }
 }

 void onTriggerStay(Collider other)
 {
     if (other.name == "Damage")
     {
         if (!onCD && currentHealth > 0)
         {
             StartCoroutine(coolDownDmg());
             CurrentHealth -= 1;
         }
     }
     if (other.name == "Health")
     {
         if (!onCD && currentHealth < MaxHealth)
         {
             StartCoroutine(coolDownDmg());
             CurrentHealth += 1;
         }
     }
 }

 private void MapValues(float x, float inMin, float inMax, float outMin, float outMax)
 {
     return(x - inMin) * (outMax - outMin) / (inMax - inMin) + (outMin);
 }

}

Comment
Add comment · Show 4
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 gjf · Nov 07, 2015 at 11:12 PM 0
Share

it's going to be tough to help you without more information about what's wrong.

what's the expected behavior? what's the actual behavior? any error messages? etc.

try formatting the entire code too - any error message will be harder to see since the line numbers in the listing won't match...

avatar image klovaaxel1000 gjf · Nov 08, 2015 at 09:00 AM 0
Share

i have typed out the error on line 54 (according to web) and it says: Unexpected symbol `healthTransform' the error is on line 55 (according to web)

sorry for bad english

avatar image OctoMan · Nov 09, 2015 at 11:55 AM 0
Share

Press F7 in $$anonymous$$onobehavior and tell us the result, if there is any.

avatar image klovaaxel1000 OctoMan · Nov 09, 2015 at 02:59 PM 0
Share

it tells me nothing.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AngryTilde · Nov 09, 2015 at 12:08 PM

I would suggest looking at line 55 (or 54) again, the compiler error is right something isn't right there and it thinks that line 54 and 55 are part of the same statement rather then two separate statements.

Hint: It's something that beginners, amateurs and even professionals sometimes miss.

There's a few other errors through out but I think you will recognise them with the help of the compiler errors (Which it should spout out once the original error is fixed), they are fairly minor ones.

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 klovaaxel1000 · Nov 09, 2015 at 04:28 PM 0
Share

Thx i completely missed a ";".

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't test the game 0 Answers

Issue referencing a method that exists in a component that is only decided at runtime 1 Answer

How to make a script that could activate a aniamtion by activating a switch? 0 Answers

How do I change the coordinates of the GameObject to the first cube in the generated grid? 0 Answers

I am having trouble with this melee script. It is keep telling me: Required to access non static member play. 0 Answers


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