• 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 jay55555 · Feb 24, 2015 at 07:44 PM · stars

3 star reward system

how would you alter script so that when player scores a certain amount of points (5 points) within certain amount of time they are ranked by 3 star system

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class PlayerMovement : MonoBehaviour {

 //reference to star images
 private GameObject star1;
 private GameObject star2;
 private GameObject star3;
 
 //reference to next button
 private GameObject buttonNext;
 
 protected string currentLevel;
 protected int worldIndex;
 protected int levelIndex;
 bool isLevelComplete ;
 //timer text reference
 public Text timerText;
 //time passed since start of level
 protected float totalTime = 0f;
 
 // Use this for initialization
 void Start () {
     //set the level complete to false on start of level
     isLevelComplete = false;
     //get the star images
     star1 = GameObject.Find("star1");
     star2 = GameObject.Find("star2");
     star3 = GameObject.Find("star3");
     //get the next button
     buttonNext = GameObject.Find("Next");
     //disable the image component of all the star images
     star1.GetComponent<Image>().enabled = false;
     star2.GetComponent<Image>().enabled = false;
     star3.GetComponent<Image>().enabled = false;
     //disable the next button
     buttonNext.SetActive(false);
     //save the current level name
     currentLevel = Application.loadedLevelName;
 }
 
 // Update is called once per frame
 void Update () {
     //check if the level is completed
     if(!isLevelComplete){
         //update the timer value
         totalTime += Time.deltaTime;
         //display the timer value 
         timerText.text = "TIME: "+totalTime.ToString();
         Debug.Log(totalTime);

     }
 }
 
 void OnTriggerEnter(Collider other){
     if(other.gameObject.name=="Comet"){
         //set the isLevelComplete flag to true if the player hits an object with name Goal
         isLevelComplete = true;
         if(totalTime<5){
             star3.GetComponent<Image>().enabled = true;
             UnlockLevels(3);   //<span id="IL_AD4" class="IL_AD">unlock</span> <span id="IL_AD2" class="IL_AD">next level</span> funxtion 
         }
         else if(totalTime<10){
             star2.GetComponent<Image>().enabled = true;
             UnlockLevels(2);   //unlock next level funxtion 
         }
         else if(totalTime<15){
             star1.GetComponent<Image>().enabled = true;
             UnlockLevels(1);   //unlock next level funxtion 
         }
         buttonNext.SetActive(true);
         
     }
 }
 
 public void OnClickButton(){
     //load the World1 level 
     Application.LoadLevel("World1");
     
 }
 
 protected void  UnlockLevels (int stars){
     
     //set the playerprefs value of next level to 1 to unlock
     //also set the playerprefs value of stars to display them on the World levels menu
     for(int i = 0; i < LockLevel.worlds; i++){
         for(int j = 1; j < LockLevel.levels; j++){               
             if(currentLevel == "Level"+(i+1).ToString() +"." +j.ToString()){
                 worldIndex  = (i+1);
                 levelIndex  = (j+1);
                 PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),1);
                 //check if the current stars value is less than the new value
                 if(PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars")< stars)
                     //overwrite the stars value with the new value obtained
                     PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars",stars);
             }
         }
     }
     
 }
 
 

}

Comment
Add comment · Show 2
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 NoseKills · Feb 25, 2015 at 05:21 AM 0
Share

If it works and doesn't cause problems, I wouldn't. Do you have a problem with the script?

avatar image jay55555 · Feb 25, 2015 at 04:23 PM 0
Share

the script works because i got it from http://www.thegamecontriver.com/2014/10/create-star-rating-reward-system-unity.html but i want to change it to respond to a certain amount of points, right now the game ends once it collides with a on trigger enter and thats to soon, im thinking that i have to change some things around line 51 but im unsure. thanks for your help

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Level stars on levels menu 1 Answer

Sun and Nebula Tutorial 3 Answers

Mesh (custom shader) appears in front of particles (default shader)? 1 Answer

Open Worlds on the basis of stars 1 Answer

Weapons Range Projectile script 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