• 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 Jellyman · May 17, 2012 at 01:21 AM · guihealthbar

if guiTexture .pixcelInset.width < 0 dead = true

hi im having trouble i want to make a functon update that says:

if guiTexture.pixcelInset.width < 0 : dead = true

its for my healthbar but every way i have tried hasn't worked and i haven't found much googling it can anybody help?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · May 17, 2012 at 01:22 AM

pixelInset != pixcelInset ;)

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 hathol · May 17, 2012 at 02:28 AM

try

 if(guiTexture.pixelInset.width <= 0)
     dead = true
Comment
Add comment · Show 2 · 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 Bunny83 · May 17, 2012 at 10:42 PM 0
Share

It seems he's using boo, so his syntax is correct as far as i can tell. I don't use boo, but i have basic knowledge of the syntax ;)

The only problem i see is the spelling mistake of pixelInset

avatar image Jellyman · May 19, 2012 at 01:09 AM 0
Share

i tried:

if(guiTexture.pixelInset.width <= 0) dead = true;

there weren't any syntax errors but it doesn't seem to be doing anything my healthbar goes down on trigger with enemyFire but when it gets to 0x it keeps going into $$anonymous$$us numbers and growing backwards.

can any one help?

avatar image
0

Answer by Jellyman · May 19, 2012 at 09:14 PM

ive come up with a solution thanks to the pointers. i had to create a variable int called Health and make it the same number as the pixelInset width. then i had to add Health -="number of health taken off" to my on trigger function

heres the scripts:

//healthbar to go on guiTexture var Health : int =269;

function Update () { if(Interaction.gotHit) guiTexture.pixelInset.width -=30;

 print(Health);
 if(Interaction.gotHit)
 Health -= 30;
 
 if(Health<=0)
 Interaction.dead = true;

} function LateUpdate() { Interaction.gotHit = false;

 if(Interaction.dead)
 {
     Application.LoadLevel(0);
     dead = false;

} }

// interaction script to go on player var bullitPrefab :Transform; static var dead = false; static var gotHit = false;

function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "enemyFire") { gotHit = true;

 }
         

}

//player 1 shoot function Update() {

 if(Input.GetButtonDown("Fire1"))
 {
     var bullit =Instantiate(bullitPrefab,
                             GameObject.Find("Main Camera").transform.position,
                             transform.rotation);
                             
     bullit.rigidbody.AddForce(transform.forward * 4000);
 }
 
 
 
 var Score = cam_score.score;
 if(Score >= 650)

{ Application.LoadLevel(2); } }

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

GuiTexture above 3D objects 1 Answer

GUI healthbar 3 Answers

Detect if any GUI is being displayed on-screen? 1 Answer

percentage health bar 1 Answer

Shrink GUI 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