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 Jellyman · May 16, 2012 at 01:25 PM · guitexturehealthbar

how would you make guiTexture.pixcelInset.width a variable?

Hi im having trouble with my game respawn I want the respawn sequence to be triggered when the guiTexture.pixcelInset.width is <0 but i keep getting this error:

Assets/script/HealthControl.js(1,22): BCE0018: The name 'GUITexture.pixelInset.width' does not denote a valid type ('not found').

Here is my code:

 //goes on healthbar
 static var HBWidth : GUITexture.pixelInset.width;
 function Update () 
 {
     if(Interaction.gotHit)
     guiTexture.pixelInset.width -=10;
 }
 function LateUpdate()
 {
     Interaction.gotHit = false;
 }
 
 //goes on player1
 static var gotHit = false;
 function OnTriggerEnter(hit : Collider)
 {
     if(hit.gameObject.tag == "enemyFire")
     {
         gotHit = true;
     }
     else
     {
         if(HBWidth<0)
         {
             dead = true;
         }
     }
 }

 

please help thanks

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 Jellyman · May 16, 2012 at 02:57 PM 0
Share

in hindsight i shall add the whole code including all the variables:

HealthControl //goes on healthbar static var HBWidth : GUITexture.pixelInset.width;

function Start () {

}

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

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

Interaction //goes on player1 var bullitPrefab :Transform;

static var gotHit = false; static var dead = false;

function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "enemyFire") { gotHit = true; } else { if(HBWidth<0) { dead = true; } }

}

//player 1 shoot function Update() { if(Input.GetButtonDown("Fire1")) { var bullit =Instantiate(bullitPrefab, GameObject.Find("$$anonymous$$ain Camera").transform.position, Quaternion.identity);

     bullit.rigidbody.AddForce(transform.forward * 2700);
 }

}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · May 16, 2012 at 03:06 PM

You are trying to access pixelInset as if it was a static var but it is not, hence the compiler output. You need the reference of the component to access it. You have the property guiTexture or the function GetComponent for that.

However, that's still won't work. Float isn't a class and HBWidth will not be a reference, which means it will remains constant when pixelInset changes.

You have many ways to do this. you could call a function returning a bool in player1's OnTriggerEnter (but you need a ref of healthbar), or do the test inside healthBar and tell the player if he is dead, but you'd need the ref of the player.

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 Jellyman · May 16, 2012 at 03:10 PM 0
Share

cool give me a $$anonymous$$ute to absorb that and make the changes then see how it goes thanks

avatar image Jellyman · May 16, 2012 at 09:57 PM 0
Share

I have tried to follow what you have said and i have altered my code like this:

//HealthControl

var healthWidth = GetComponent(guiTexture.pixelInset.width);

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

else { healthWidth : <0; dead = true;

}

 Interaction.dead = true;

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

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

}

but now i keep getting this error: Assets/script/HealthControl.js(15,9): BCE0043: Unexpected token: healthWidth.

can anyone please help thanks

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

Dynamic Health Bar in unity 4.6 0 Answers

Help With Enemy Health bars 3 Answers

Issue with GUITexture width. 1 Answer

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Minion floating healthbar over the head 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