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 Jay_Adams · Nov 28, 2010 at 10:10 PM · guiresetlives

Resting health images.. convoluted 3d tut + TT tu script

I worked through the Tornado Twins tut, so my health (GUI Texture) is based on that. Then I added a damage counter (GUI Text). Everything was working great (crash-die-game over, or take 6 hits, die, game over) and everything would reset properly.

BUT, my GUI wouldn't scale with project output, so I went back to the 3d lerpz tut and got my hud working on that system. It scales now so that's good. Everything is in one script and I'm not using the gui text or gui texture anymore.

Still works pretty good, but one issue left.

If I take one hit, crash into the ground and replay (from game over menu) I start with 1 hit off my health bar, and it only takes 5 hits to kill me (not 6). But if I just take 6 hits I die and images reset.

static var LIVES = 6; static var HITS = 0;

var guiSkin: GUISkin; var nativeVerticalResolution = 1200.0;

// main decoration textures: var UFO_healthImage: Texture2D; var UFO_healthImageOffset = Vector2(0, 0);

// the health 'pie chart' assets consist of six textures with alpha channels. Only one is ever shown: var UFO_DamageImages : Texture2D[]; var UFO_DamageImagesOffset = Vector2(0, 0);

var destructionCounterOffset = Vector2(0, 0);

function OnGUI () { // Similarly, health needs to be clamped to the number of pie segments we can show. // We also need to check it's not negative, so we'll use the Mathf Clamp() function: var UFO_healthIndex = Mathf.Clamp(LIVES, 0, UFO_DamageImages.length);

// Set up gui skin GUI.skin = guiSkin;

 // Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
 GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 

 // Health & lives info.
 DrawImageBottomAligned( UFO_healthImageOffset, UFO_healthImage); // main image.

 // now for the pie chart. 
 var UFO_DamageImage = UFO_DamageImages[UFO_healthIndex-1];
 DrawImageBottomAligned( UFO_DamageImagesOffset, UFO_DamageImage );

 //destruction counter placement
 DrawLabelBottomRightAligned( destructionCounterOffset, CollisionScript.playerPoints.ToString ( "Destruction: " + CollisionScript.playerPoints) );

}

//for health images function DrawImageBottomAligned (pos : Vector2, image : Texture2D) { GUI.Label(Rect (pos.x, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image); }

//for damage count e\text function DrawLabelBottomRightAligned (pos : Vector2, text : String) { GUI.Label(Rect (pos.x, nativeVerticalResolution - pos.y, 1200, 120), text); }

/////////// //keep track of hits to player function Update () { print("Lives: " +LIVES+"Hits: "+HITS); //Lives = 6, hits = 0

 switch(LIVES)
 {
     case 6:
     break;

     case 5:
     break;

     case 4:
     break;

     case 3:
     break;

     case 2:
     break;

     case 1:
     break;

     case 0:
     UFO_Player.dead = true; //dead == true to play anim, UFO_Player script
     //yield WaitForSeconds(5); //stalls to return to menu, ///////////////////////You were shot down Text artwork
     //quit game
     Application.LoadLevel(2);
     CollisionScript.playerPoints = 0;
     LIVES = 6;
     HITS = 0;

     break;
 }

}

My player crash code is in my collision script, this worked fine before going to the lerpz style gui:

else { //player hits building, instant death if((hit.gameObject.tag == "building") && (gameObject.tag == "Player"))// registers player crash (ground or building or large object) { Destroy(gameObject); var playerCrashBuilding = Instantiate (kablammo, gameObject.transform.position, Quaternion.identity); //Destroy(hit.gameObject); //could destroy building too Debug.Log("Player crashed"); gotHit = true;

 //yield WaitForSeconds(5);
     Application.LoadLevel(2);
     CollisionScript.playerPoints = 0;
     LIVES = 6;
     HITS = 0;
 }

I think I need to change this var or at least the index to my health index element 5 (no damage picture) but can't for the life of me figure out how. Have tried calling scriptname.UFO_DamageImage... in a few ways, but get error saying it's not a part of that script (possibly because it's inside the OnGUI function? Tried moving it out with other vars but that didn't work.

var UFO_DamageImage = UFO_DamageImages[UFO_healthIndex-1];
DrawImageBottomAligned( UFO_DamageImagesOffset, UFO_DamageImage )

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

0 Replies

· Add your reply
  • Sort: 

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

No one has followed this question yet.

Related Questions

GUI background changed, don't know how to reset it. 2 Answers

DontDestroyOnLoad Game Score/Lives 1 Answer

Problem with texture to reset and re-enter the same texture 0 Answers

I'm having issues increasing my lives 2 Answers

Pick up objects 2 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