Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Sep 17, 2020 at 02:14 PM by Wira38 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Wira38 · Sep 16, 2020 at 04:21 AM · puzzle

hi, i need some help with a puzzle script

hi, i'm currently trying to make a 2D mechanic game and i was using a click and drag script but when i try to restart a level or in this case move to a new scene the script for enable it turn on automatically , this code should only turn on if the 2 others script condition is true, is there any way to fix this?

using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class acidnexttutorial : MonoBehaviour
 {
     public GameObject acid, acidshadow, dialog1,dialog2,dialog3, back;
 
 
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
 
         if (akifunnel.done == true)
 
         {
             acid.gameObject.SetActive(true);
             acidshadow.gameObject.SetActive(true);
             dialog1.gameObject.SetActive(false);
             dialog2.gameObject.SetActive(true);
         }
         
 
         if (acidlock.done == true)
         {
             back.gameObject.SetActive(true);
             dialog2.gameObject.SetActive(false);
             dialog3.gameObject.SetActive(true);
         }
        
 
 
 
     }
 }


[1]: /storage/temp/167605-error-script.png

error-script.png (49.9 kB)
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 streeetwalker · Sep 16, 2020 at 06:33 AM 0
Share

@Wira38, I understand you have a problem, but it's not clear what you mean. Are you trying to set values in one scene and have them carry over to affect the next scene (or on reload of a scene?)

avatar image Wira38 streeetwalker · Sep 16, 2020 at 06:36 AM 0
Share

on reload of a scene

2 Replies

  • Sort: 
avatar image
0

Answer by Wira38 · Sep 16, 2020 at 06:45 AM

To be clear, the script above will enable a gameobject if the drag and drop script(example the akifunnel) "done" bool value is true, but the problem here is when trying to replay the level or move to another scene the script automatically enable the object and disable the drag and drop script

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 streeetwalker · Sep 16, 2020 at 06:52 AM

@Wira38, it doesn't matter whether you are talking about loading a different scene or reloading the same scene, all variables are reset to the starting values for the scene. Reloading a scene is just like moving to a new scene. The newly loaded scene knows nothing about the previous scene.

If you want values to persist from scene to scene so you can set up the loaded scene based on what happened in the previously loaded scene, there are several ways to do it. Here is an easy method that has some drawbacks, and you should google about persistent/keeping values between scenes to learn more about why and what some potentially better alternatives are.

Create a static class in a script file. The static class will keep its values across scenes. Do not attempt to attach this to any game object - it will simply sit in your project folder and will be accessible from any class script in any scene.

For example

 public static class GlobalValues {
          public static bool hasGun = false;
 }
     
     // now from any script in any scene you can get or set hasGun
     GlobalValues.hasGun = true;
     
     // if you set hasGun in one scene, you can read the value in another.
 


Please note that this method does not keep data if you quit the game and restart. If you need to save data between game loads, then do a search and you will find a number of methods that involve serializing your game data and saving it to a file.

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

Follow this Question

Answers Answers and Comments

208 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

Related Questions

How to determine the number of bubbles that share that same color in a cluster and return as a list? 1 Answer

How to check if the area is filled or not? 1 Answer

Create 'call and response' music puzzle 0 Answers

Collecting puzzle pieces in my platformer game 0 Answers

Avoid changes if I dont changing my position. 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