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 /
  • Help Room /
avatar image
0
Question by potjam100 · Jun 20, 2019 at 12:14 PM · scripting problemscenesstuck

need help transferring something from 1 scene to the other

Hi I'm trying to bring a script that enables gameobjects (stars) in the canvas from one scene to the other, upon level completion. What I mean by this is: -Player gets a score in the level and completes it -the score is then taken to a new scene and placed on a level complete ui (it's a new scene because of a problem I had, listed at the bottom of this post) -the script shown below takes effect, displaying 1-3 stars based on performance (think of candy crush and similar mobile games) -the script itself counts how many collectable items are in the level and how many have been collected. It then uses this information to make a percentage out of it and award stars based on the percentage collected by enabling the corresponding gameobject(s)

Problem is I have no idea how to do this. It's worth noting that I've only been using unity for 2 weeks or so, so I'm still really new to it all. Script is here:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class LevelStars : MonoBehaviour
 {
     public GameObject[] stars;
     private int coinsCount;
     private int diamondCount;
     private int starCount;
 
     private void Start()
     {
         coinsCount = GameObject.FindGameObjectsWithTag("Coin").Length;
         diamondCount = GameObject.FindGameObjectsWithTag("Diamond").Length;
         starCount = GameObject.FindGameObjectsWithTag("Star").Length;
     }
 
     public void StarsAchieved()
     {
         int coinsLeft = GameObject.FindGameObjectsWithTag("Coin").Length + 
             GameObject.FindGameObjectsWithTag("Diamond").Length + 
             GameObject.FindGameObjectsWithTag("Star").Length;
         int coinsCollected = coinsCount + diamondCount + starCount - coinsLeft;
 
         float percentage = float.Parse(coinsCollected.ToString()) / float.Parse(coinsCount.ToString()) * 100f;
 
         
         if (percentage >= 0f && percentage < 33)
         {
             Debug.Log("You suck!");
         }
         
         else if (percentage >= 33f && percentage < 66)
         {
             stars[0].SetActive(true);
             Debug.Log("You got 1 star.");
         }
 
         else if (percentage >= 66f && percentage < 99)
         {
             stars[0].SetActive(true);
             stars[1].SetActive(true);
             Debug.Log("You got 2 stars!");
         }
 
         else if (percentage >= 100)
         {
             stars[0].SetActive(true);
             stars[1].SetActive(true);
             stars[2].SetActive(true);
             Debug.Log("M-m-m-MAXIMUM SCORE!!!!!111");
         }
 
         
     }    
     }

My original problem was trying to make the score from the game carry over to a level complete screen within the same scene. I couldn't get it working so I found a workaround that involved making another scene and transitioning to it, which fixed my problem using playerprefs. However, in doing this, my LevelStars script is now completely broken. Ive tried dontdestroyonload to move the gameobject containing the script and array, but all the reference objects are ''missing'' as a result.

I've also looked into playerprefs but I don't know how to accomplish it, if its even possible.

Please help! I'm pulling my hair out over this :)

I

Comment
Add comment · Show 1
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 potjam100 · Jun 24, 2019 at 08:21 AM 0
Share

Okay so I fixed my problem by solving my initial problem with the score text and abandoning the idea of another scene etc.

I am still seeking a solution for this though, because I want to save the value of the stars earned and retrieve it on the level select screen to show the stars earned for that level. Anybody able to shed some light on this?

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.

Follow this Question

Answers Answers and Comments

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

change a created transform in a script from another one 1 Answer

I have a problem about my Arkanoid game. Please help! 0 Answers

how reload scene when rotate screen android 1 Answer

Problem with script in multiple scenes needing to refer to FPS Controller. 1 Answer

Complicated level change problem 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