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 $$anonymous$$ · Apr 02, 2019 at 05:59 PM · levelsstarscollect

Number of stars

Hi!


I want to see the number of stars in the level below every world.


Besides the victory panel, I want to dynamically locate the results of the stars on the levels.


When I win the first level , the same number of stars are shown below the numbers of all the levels.


I want to dynamically see the number of stars in each level


This is the code for the stars


 public class Stars : MonoBehaviour {
 
     public static int stars;
     public static int allstars;
     public Image[] starphoto;
     public Sprite fullstar;
     public Sprite emptystar;
     
 
     void Start(){
         stars = stars;
         allstars = 3 ;
     }
 
 
     void Update(){
         if(stars > allstars){
             stars = allstars;
         }
         for (int i = 0; i < starphoto.Length; i++){
             if (i < stars){
                 starphoto[i].sprite = fullstar;
             } else {
                 starphoto[i].sprite = emptystar;
             }
 
             if (i < allstars){
                 starphoto[i].enabled = true;
             } else {
                 starphoto[i].enabled = false;
             }
         }
     }
 }









Comment
Add comment · Show 9
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 Magso · Apr 02, 2019 at 07:14 PM 0
Share

Your question isn't very clear or specific, are you asking how to position the stars?

avatar image $$anonymous$$ Magso · Apr 03, 2019 at 06:19 AM 0
Share

yes, Besides the victory panel, I want to dynamically locate the results of the stars on the levels.

avatar image $$anonymous$$ Magso · Apr 03, 2019 at 06:24 AM 0
Share

This code works for the stars, I want to see the stars in every world underneath the world, how it is done?

avatar image surfuay · Apr 02, 2019 at 08:15 PM 0
Share

so are you trying to see how many stars are available in the current level or the total number of stars you've collected thus far and retain a running tally regardless of the level you're in

avatar image $$anonymous$$ surfuay · Apr 03, 2019 at 06:20 AM 0
Share

Besides the victory panel, I want to dynamically locate the results of the stars on the levels.

avatar image $$anonymous$$ · Apr 03, 2019 at 06:24 AM 0
Share

This code works for the stars, I want to see the stars in every world underneath the world, how it is done?

avatar image Magso $$anonymous$$ · Apr 03, 2019 at 04:25 PM 0
Share

Parent the stars to an empty gameObject then attach the script to that parent object and drag it to the assets to create a prefab of it, you can then use it in any level you want by dragging it to the hierarchy or instantiate it by a script.

avatar image $$anonymous$$ Magso · Apr 03, 2019 at 06:23 PM 0
Share

It puts all the results of the first world

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Apr 03, 2019 at 07:12 PM

Change the int all stars to an array of ints, since you need to compare the amount of stars per level, you will need to add the stars value depending in the current scenebuildindex and just iterate over the array for displaying the stars

Comment
Add comment · Show 5 · 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 $$anonymous$$ · Apr 03, 2019 at 07:37 PM 0
Share

thank you, I'll try it now

avatar image $$anonymous$$ · Apr 04, 2019 at 05:09 PM 0
Share

I do not understand how to do it

avatar image xxmariofer $$anonymous$$ · Apr 04, 2019 at 07:43 PM 0
Share

What is your exact issue? Do you havr a scend per level?

avatar image $$anonymous$$ xxmariofer · Apr 05, 2019 at 09:07 AM 0
Share

Each level is one scene

Show more comments
avatar image
0

Answer by surfuay · Apr 03, 2019 at 07:37 PM

before you get to crazy on trying to recode anything, 1 problem that may be preventing you from showing the running tally of stars accrued is that your statement

stars = allstars

is backwards.

so your stars = stars is fine, allstars = 3 is fine but in the update method what's happening is you are equating stars to allstars anytime stars is greater than allstars, so its resetting the displayed int back at 3 everytime. the simple fix would be allstars = stars.

obviously in math on paper A = B is the same as B = A but in coding what's happening is that it reads the first variable and equates it to the second rather than making which ever is higher the master variable.

let me know if that works, if not there may be a few other things to add that I think may make it work

Comment
Add comment · Show 7 · 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 $$anonymous$$ · Apr 04, 2019 at 05:14 PM 0
Share

didn't work Dear.

avatar image surfuay $$anonymous$$ · Apr 04, 2019 at 05:19 PM 0
Share

ok try allstars = all stars + stars;

that should on each update allow for your allstars int to change.

so in the level you'll continue just to have whatever stars you collected there but your allstars location will have the previous total plus your new total.

only hitch I can think is it may just start adding the stars infinitely since you call the function every frame.

avatar image $$anonymous$$ surfuay · Apr 04, 2019 at 05:24 PM 0
Share

In 12 line?

Show more comments
avatar image surfuay · Apr 04, 2019 at 05:15 PM 0
Share

do u have a canvas? please don't call me dear

avatar image $$anonymous$$ surfuay · Apr 04, 2019 at 05:49 PM 0
Share

yes, all stars are in the canvas

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

103 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 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 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 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 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 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 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

how to give star score once per each level? 0 Answers

Dynamic Star System with PlayerPrefs 1 Answer

How to make PlayerPrefs delete if the player didn't touch game finish collider 1 Answer

Collestion of objects 3 Answers

Multilevel shooter? 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