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 Afassolas · Oct 17, 2014 at 07:08 AM · imagebuttons4.6stars

Help with 3 star reward system

I am trying to make a 3 star rating system for a project like angry birds. In my case instead of stars as rewards I use cars.

I have 2 buttons on the scene Level1 and Level2

and four images for the star(car) rewards OneCarSprite TwoCarSprite ThreeCarSprite NoCarSprite

I am using Playmaker to pass the following variables to a script.

LevelToReward ( which holds a string with the name of the level to be rewarded Level1 or Level2 )

and carscore (which is the number of stars(cars) the level will be awarded.

I attach the script to each Buttons (Level1 and Level2)

My problem is that the script works for button1 and when i click on button2 it works but I loose the reward that was assigned to button1

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using HutongGames.PlayMaker;
 
 public class CarsRewardSystem : MonoBehaviour {
 
     public Sprite OneCarSprite;
     public Sprite TwoCarSprite;
     public Sprite ThreeCarSprite;
     public Sprite NoCarSprite;
     public string LevelToReward;
 
 
     Image images; // declare of Image type
     public Button l1; // declare of Button type
     public Button l2; 
 
     // Use this for initialization
     void Start () {
 
         LevelToReward = FsmVariables.GlobalVariables.GetFsmString("levelCompleted").Value; // get variable from Playmaker FSM
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }

     void Cars(int carscore) {
         Debug.Log (LevelToReward);
         Debug.Log (carscore);
 
         // changes the sprites to allow rewards of 1 , 2, 3 cars according to score
         images = gameObject.GetComponent<Image>(); // get the component of Image method
         l1 = gameObject.GetComponent<Button>(); // get the component of Button method.
 
         l2 = gameObject.GetComponent<Button>(); // get the component of Button method.
 
 
         if (carscore == 1 && LevelToReward == "Level1") {
             //images.sprite = OneCarSprite;
             l1.image.sprite = OneCarSprite;
             
 
 
         } else if(carscore == 2 && LevelToReward == "Level1") {
             //images.sprite = TwoCarSprite;
             l1.image.sprite = TwoCarSprite;
 
 
         } else if(carscore == 3 && LevelToReward == "Level1") {
             //images.sprite = ThreeCarSprite;
             l1.image.sprite = ThreeCarSprite;
 
 
         } else if (carscore >3 || carscore<1){
             l1.image.sprite = NoCarSprite;
 
 
         }
 
             if (carscore == 1 && LevelToReward  == "Level2") {
                 //images.sprite = OneCarSprite;
                 l2.image.sprite = OneCarSprite;
 
                 
                 
         } else if(carscore == 2 && LevelToReward  == "Level2") {
                 //images.sprite = TwoCarSprite;
                 l2.image.sprite = TwoCarSprite;
                 
                 
         } else if(carscore == 3 && LevelToReward  == "Level2") {
                 //images.sprite = ThreeCarSprite;
                 l2.image.sprite = ThreeCarSprite;
                 
                 
             } else if (carscore >3 || carscore<1){
                 l2.image.sprite = NoCarSprite;
 
 
         }
 
         }
 
 }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GluedBrain · Nov 01, 2014 at 04:09 AM

Check this article which covers exactly how to do this from scratch..

Star reward system - Unity

Comment
Add comment · 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
0

Answer by thelime · Oct 17, 2014 at 10:56 AM

Lets see if i understand you. You play level 1 with button 1 and when done you get the rewards? And after you play level 2 with button 2 and you are done you get the rewards but the result from level 1 is missing? If it is like that you have the problem here

    } else if (carscore >3 || carscore<1){
             l1.image.sprite = NoCarSprite;
 
 // you dont checking if it is level1 you have played so it will always change it to noCarSprite
 add this to
 
 && LevelToReward == "Level1"

and it should work :)

Comment
Add comment · Show 4 · 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 Afassolas · Oct 17, 2014 at 11:20 AM 0
Share

That's my problem yes. I will check your solution in a couple of hours. Thanks for your time :)

avatar image thelime · Oct 17, 2014 at 11:45 AM 0
Share

okey if it still is problem post it here and i will try to help you!

avatar image Afassolas · Oct 17, 2014 at 02:36 PM 0
Share

no luck it is not working. At other parts of my code I am using PlayerPrefs to save and load the rewards of each level. $$anonymous$$aybe there is the problem. If this part of code is correct.

avatar image thelime · Oct 19, 2014 at 08:22 PM 0
Share

yes maybe. if you whant more help you need to post more kode and show how you save and loade data

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

[4.6 - UI] Calling function on button click via script 1 Answer

UI 4.6 Image blocks Mouse Click 0 Answers

9 Sliced Image Is Bleeding Edges 0 Answers

Multi Coloured Buttons 0 Answers

[Solved]Why my Unity Button's Positions are different. 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