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 Taragon · Mar 08, 2011 at 11:42 PM · guitimerlerpz3dplatformtutorial

3Dplatformer tutorial GUI script - adding a timer GUI

I have this idea where depending upon whether Lerpz triggers the enemy or not, the timer decreases in value (along with continuously decreasing by seconds). The function of the timer is to allow game time (and can in essence decrease regularly and by a trigger point). I would want this timer to show up as a, "GUI" object like the fuel cells and life icons at the bottom of the screen. The timer can be in the upper top right or left corner of the screen, and I thought of writing it in the GameHUD script of the Lerpz game. Please take a look and let me know if it makes sense to add the timer script here. The GUISkin is basically what I need. So, I need it to be in the same format as the others. Thanks for the help in advance.

// GameHUD: Platformer Tutorial Master GUI script.

// This script handles the in-game HUD, showing the lives, number of fuel cells remaining, etc.

var guiSkin: GUISkin; var nativeVerticalResolution = 1200.0;

// main decoration textures: var healthImage: Texture2D; var healthImageOffset = Vector2(0, 0);

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

// the lives count is displayed in the health image as a text counter var livesCountOffset = Vector2(425, 160);

// The fuel cell decoration image on the right side var fuelCellsImage: Texture2D; var fuelCellOffset = Vector2(0, 0);

// The counter text inside the fuel cell image var fuelCellCountOffset = Vector2(391, 161);

private var playerInfo : ThirdPersonStatus;

// Cache link to player's state management script for later use. function Awake() { playerInfo = FindObjectOfType(ThirdPersonStatus);

if (!playerInfo)
    Debug.Log("No link to player's state manager.");

}

function OnGUI () {

var itemsLeft = playerInfo.GetRemainingItems(); // fetch items remaining -- the fuel cans. This can be a negative number!

// 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 healthPieIndex = Mathf.Clamp(playerInfo.health, 0, healthPieImages.length);

// Displays fuel cans remaining as a number.
// As we don't want to display negative numbers, we clamp the value to zero if it drops below this: if (itemsLeft < 0) itemsLeft = 0;

// 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( healthImageOffset, healthImage); // main image.

// now for the pie chart. This is where a decent graphics package comes in handy to check relative sizes and offsets. var pieImage = healthPieImages[healthPieIndex-1]; DrawImageBottomAligned( healthPieImageOffset, pieImage );

// Displays lives left as a number. DrawLabelBottomAligned( livesCountOffset, playerInfo.lives.ToString() );

// Now it's the fuel cans' turn. We want this aligned to the lower-right corner of the screen: DrawImageBottomRightAligned( fuelCellOffset, fuelCellsImage);

DrawLabelBottomRightAligned( fuelCellCountOffset, itemsLeft.ToString() );

}

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

function DrawLabelBottomAligned (pos : Vector2, text : String) { GUI.Label(Rect (pos.x, nativeVerticalResolution - pos.y, 100, 100), text); }

function DrawImageBottomRightAligned (pos : Vector2, image : Texture2D) { var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width; GUI.Label(Rect (scaledResolutionWidth - pos.x - image.width, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image); }

function DrawLabelBottomRightAligned (pos : Vector2, text : String) { var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width; GUI.Label(Rect (scaledResolutionWidth - pos.x, nativeVerticalResolution - pos.y, 100, 100), text); }

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

Timer script Update with Pickup 0 Answers

Timer script & game hud 0 Answers

Instantiating GUI text after 2nd object is destroyed 1 Answer

Lerpz Escapes question 1 Answer

drag lerpz.fbx from 3DPlatFormTutorial to another project 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