playMaker

Author Topic: 3 star rating system using playmaker help  (Read 3401 times)

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
3 star rating system using playmaker help
« on: October 16, 2014, 11:16:01 PM »
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

here is the script :

Code: [Select]
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) {

// 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;


}

}




}

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4528
    • View Profile
    • jinxtergames
Re: 3 star rating system using playmaker help
« Reply #1 on: October 17, 2014, 09:43:27 AM »
i made mine work like on angry birds this way :


upload images free

the 0,1,2 and 3 states will set the gui texture (but can do anything you want ofc)

i use playerPrefs so it stays saved when game is stopped

so if a certain score is met it will set the playerPrefs  to 1,2 or 3
and give 1,2 or 3 stars
« Last Edit: October 17, 2014, 09:53:54 AM by djaydino »
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: 3 star rating system using playmaker help
« Reply #2 on: October 17, 2014, 10:35:08 AM »
Yes and how do you change the stars images on the level selection buttons ? I am using unity 4.6 with the new GUI. My problem is not the rewards my problem is showing them on all level selection buttons since they are saved with PlayerPrefs.

My system works but for some reason it looses the stars rewarded image of the previous level i have played and saved.
« Last Edit: October 17, 2014, 10:40:52 AM by Boom7Games »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4528
    • View Profile
    • jinxtergames
Re: 3 star rating system using playmaker help
« Reply #3 on: October 17, 2014, 11:01:50 AM »
im just using set Gui texture but i am still on 4.5 i don't know if it is the same on 4.6

but i think it might have something to do with your playerprefs

is the key on both button different?

do you have an asset to check your playerPrefs (Player Prefs Editor for example )
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: 3 star rating system using playmaker help
« Reply #4 on: October 17, 2014, 11:19:25 AM »
Yes the key is certainly different but i don't have an asset as you mention. I use a debug script to delete all prefs in order to check how they work
« Last Edit: October 17, 2014, 11:20:56 AM by Boom7Games »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4528
    • View Profile
    • jinxtergames
Re: 3 star rating system using playmaker help
« Reply #5 on: October 17, 2014, 12:30:20 PM »
the way i have it is :
when a game ends, the score will be compared to
the high-score saved in playerPref key "highscore_Level_01"
if the score is higher than the high-score it will check the score value for the stars,
if the score is 100 it will set the int value from  playerpref key "Stars_Level_01" to 1 , (if 200 to 2 and 300 to 3)
and then i use the fsm on each of my textures (objects)
with a different key for each level

all done in playmaker btw
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4528
    • View Profile
    • jinxtergames
Re: 3 star rating system using playmaker help
« Reply #6 on: October 17, 2014, 12:37:49 PM »
maybe you can use SwapSprite to change the images
you can find the action in the ecosystem.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

Boom7Games

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: 3 star rating system using playmaker help
« Reply #7 on: October 17, 2014, 02:28:55 PM »
so if you have  50 levels in the game you have to do this 50 different times to check which rewards each level will get?
And have 50 different keys for level rewards to save and load ?

I am interested in you showing me the use of the texture actions if you can

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4528
    • View Profile
    • jinxtergames
Re: 3 star rating system using playmaker help
« Reply #8 on: October 17, 2014, 06:35:41 PM »
in your script i noticed your using sprites so i think you need to use SwapSprite

as i use gui texture i just do set gui texture.
and i have 60 levels now and yes all 60 Gui texture has 1, but its just copy paste and change the key... so its not so much work, i could do it in 1 fsm but i would still have to set each level.

image upload no limit

there are some assets that can make it easier like  Mad Level Manager wich also has playmaker Actions.
but i was already @ Level 40 when i saw those so i continued manually :)
i might get this 1 for my next project
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions