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 cSharpNoob · Aug 07, 2013 at 04:51 AM · c#scriptingproblem

help for life using guiTexture

Hello im a noob/beginner programmer of C# and right now

im finding a way how to make a life using guitexture

and i found a quite useful tutorial and current using it right now

i just have a problem, i dont know , how am i supposed to make it leveltoload to my

gameOver Scene

using UnityEngine; using System.Collections;

public class Health : MonoBehaviour {

 public int startHealth;
 public int healthPerHeart;
 
 public int maxHealth;
 public int currentHealth;
 
 public Texture[] heartImages;
 public GUITexture heartGUI;
 
 private ArrayList hearts = new ArrayList();
 
 // Spacing:
 public float maxHeartsOnRow;
 private float spacingX;
 private float spacingY;
 
 
 void Start () {
     spacingX = heartGUI.pixelInset.width;
     spacingY = -heartGUI.pixelInset.height;
 
     AddHearts(startHealth/healthPerHeart);
 }
 
 public void AddHearts(int n) {
     for (int i = 0; i <n; i ++) { 
         Transform newHeart = ((GameObject)Instantiate(heartGUI.gameObject,this.transform.position,Quaternion.identity)).transform; // Creates a new heart
         newHeart.parent = transform;
         
         int y = (int)(Mathf.FloorToInt(hearts.Count / maxHeartsOnRow));
         int x = (int)(hearts.Count - y * maxHeartsOnRow);

         newHeart.GetComponent<GUITexture>().pixelInset = new Rect(x * spacingX,y * spacingY,58,58);
         newHeart.GetComponent<GUITexture>().texture = heartImages[0];
         hearts.Add(newHeart);

     }
     maxHealth += n * healthPerHeart;
     currentHealth = maxHealth;
     UpdateHearts();
 }

 
 public void modifyHealth(int amount) {
     currentHealth += amount;
     currentHealth = Mathf.Clamp(currentHealth,0,maxHealth);
     UpdateHearts();
 }

 void UpdateHearts() {
     bool restAreEmpty = false;
     int i =0;
     
     foreach (Transform heart in hearts) {
         
         if (restAreEmpty) {
             heart.guiTexture.texture = heartImages[0]; // heart is empty
         }
         else {
             i += 1; // current iteration
             if (currentHealth >= i * healthPerHeart) {
                 heart.guiTexture.texture = heartImages[heartImages.Length-1]; // health of current heart is full
             }
             else {
                 int currentHeartHealth = (int)(healthPerHeart - (healthPerHeart * i - currentHealth));
                 int healthPerImage = healthPerHeart / heartImages.Length; // how much health is there per image
                 int imageIndex = currentHeartHealth / healthPerImage;

                 
                 if (imageIndex == 0 && currentHeartHealth > 0) {
                     imageIndex = 1;
                 }

                 heart.guiTexture.texture = heartImages[imageIndex];
                 restAreEmpty = true;
             }
         }
         
     }
 }
 
 

}

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 Ben-Stoneman ♦♦ · Aug 07, 2013 at 02:37 PM 0
Share

This will show you how to load a new scene.

http://docs.unity3d.com/Documentation/ScriptReference/Application.LoadLevel.html

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

15 People are following this question.

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

Related Questions

Unity Editor Crashes On Play Because of Import Script 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Playing an animation with C#? 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