Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fifaman89 · Aug 31, 2016 at 05:40 AM · c#unity 5spaceship

Hello, I am working on a spaceship game and can't get my score to show or pop up. I need help.

public class HUD : MonoBehaviour {

 public LifeIcon lifeIconObj;
 // Stores the dynamically created instances of 
 // the life icons.
 private List<LifeIcon> lifeIconInstances;

 // Contains a reference to the Text Mesh used
 // for the score text. Remember to drag drop 
 // the ScoreText game object on this variable 
 // in the editor's inspector window. 
 public TextMesh scoreTextMesh; 
 // This will contain a copy of the original text. 
 // When the text mesh is modified with dynamic
 // values, we concatenate the numeric value with 
 // this string value. 
 private string scoreText;

 // Update the score text to include the value passed
 public void updateScore (int value) {
     // Reset the text mesh's text to the orignal so 
     // the previous value is overwritten with the new one
     scoreTextMesh.text = scoreText; 
     // Add the value to the text 
     scoreTextMesh.text += value; 
 }

 public void CreateLifeIcons (int numLives){

     // Has the life icon instance list already been created? 
     if (lifeIconInstances == null) {
         // Create our list of life icons then populate
         // it with the one visually placed in the editor 
         lifeIconInstances = new List<LifeIcon> ();

         // Life Icon reference already exists so simply 
         // place it in the list. 
         lifeIconInstances.Add(lifeIconObj);

         // The positional step to offset each instanced life icon
         Vector3 positionalOffset = new Vector3(1.5f, 0, 0); 

         // Loop for each life past the first one and create a new 
         // icon for every life passed the first one
         for (int i = 1; i < numLives; ++i) 
         {
             // Create new life icon
             LifeIcon newlifeIcon; 
             newlifeIcon = Instantiate (lifeIconObj,
                 lifeIconObj.transform.position, 
                 lifeIconObj.transform.rotation) as LifeIcon; 

             // Apply positional offset
             Vector3 newPosition = newlifeIcon.transform.position; 
             newPosition.x += (positionalOffset.x * i); 
             newlifeIcon.transform.position = newPosition; 

             // Reset the scale of the icon to its identify 
             newlifeIcon.transform.localScale = new Vector3(1,1,1); 

             // Store it in our list of instances
             lifeIconInstances.Add(newlifeIcon); 

         }
     }
 }

 // Updates the life icons' active status to reflect
 // the number of lives remaining 
 public void updateLives (int numLivesRemamining){

     // Loop for each life and create a new icon for 
     // every life past the first one 
     for(int i = 0; i < lifeIconInstances.Count; ++i)
     {
         bool bActive = i < numLivesRemamining; 
         lifeIconInstances [i].gameObject.SetActive (bActive);
     }
 }
     



 // Use this for initialization
 void Start () {
     // Store a copy of the text mesh's text
     scoreText = scoreTextMesh.text;

     updateScore (10); 

     CreateLifeIcons (3); 

 }
 
 // Update is called once per frame
 void Update () {


 

 }

}

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 Landern · Aug 30, 2016 at 10:04 PM 1
Share

Come on now, there isn't any information that is helpful in your post, Are you getting an error, is the component showing on the screen in the editor when in play mode? What is your expectation from the code above, something to help you with.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unity - halo doesn't work all the time 0 Answers

Why does my Lerp only run once? 0 Answers

Enemy Ai is not working as planned 0 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