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;


		}

		}

}

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 :slight_smile:

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

Star reward system - Unity