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 clcriado0 · Jan 07, 2019 at 06:53 PM · gameobjectscenebooleanscene-switchingawake

Problem Activating a GameObject using a static Bool in other Scene

Hello, my problem is I want to press a certain button and when i press it, it will SetActive a GameObject in another Scene, I created two Scripts, the first when i do click on the button set True a public static bool and in the Second script I call it and if is true and the Bool is true then Active the GameObject, the problem is don't works I dont know Why.The first script is named "CargarPersonaje" contains the static bools and I want when i do click on a button to set the Bool to True and in other Scene turn On a GameObject.

Script 1:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class CargarPersonaje : MonoBehaviour
 {
     public string Modo_Batalla, Modo_Batalla2;
     Scene scene;
     public static bool selectCharacter1;
     public static bool selectCharacter2;
     public GameObject char01;
     public GameObject char02;
     public GameObject char03;
     public GameObject char04;
     public GameObject char05;
     public GameObject char06;
     public GameObject char07;
     public GameObject char08;
     public GameObject char09;
     public GameObject char10;
 
     void Update()
     {
         scene = SceneManager.GetActiveScene();
     }
     public void OnMouseDown()
     {
         if (Input.GetMouseButtonDown(0))
         {
                 if (char01.activeSelf)
                 {
                     selectCharacter1 = true;
                     SceneManager.LoadScene("Modo batalla2");
 
                 }
                 else if (char02.activeSelf)
                 {
                     selectCharacter2 = true;
                     SceneManager.LoadScene("Modo batalla2");
                 }
         }
 }


and the Second Script is:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CargarPersonaje2 : MonoBehaviour
 {
     public bool isPlayer1;
     public bool isPlayer2;
     public bool isPlayer3;
     public bool isPlayer4;
     void Awake()
     {
         if (CargarPersonaje.selectCharacter1 && isPlayer1 == true)
         {
             //you have been selected
             gameObject.SetActive(true);
         }
         else if (CargarPersonaje.selectCharacter2 == isPlayer2)
         {
             //you have been selected
             gameObject.SetActive(true);
         }
         else if (CargarPersonaje.selectCharacter3 == isPlayer3)
         {
             //you have been selected
             gameObject.SetActive(true);
         }
         else if (CargarPersonaje.selectCharacter4 == isPlayer4)
         {
             //you have been selected
             gameObject.SetActive(true);
         }
     }
 }


My problem is, when i do click on the button, the GameObject don't turns On.

The button is the picture on the center.

alt text

And the GameObject needed to be activated is this:

alt text

ffe6476e990c506813eef80b660f4f49.png (354.4 kB)
dos.png (431.7 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by clcriado0 · Jan 07, 2019 at 10:38 PM

@JxWolfe can you help me please?

Comment
Add comment · Show 3 · 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 JxWolfe · Jan 08, 2019 at 12:02 AM 0
Share

ok! one sec

avatar image clcriado0 JxWolfe · Jan 08, 2019 at 02:20 PM 0
Share

Please, I need really help here, i will vote you all time +1

avatar image JxWolfe JxWolfe · Jan 08, 2019 at 09:56 PM 0
Share

sorry, something came up...

basically, you need to have a controlling script with references to each of the gameObjects... that goes in the scene your loading. Turn them off on start by referencing your variable script if(VaribleScript.turnObject1Off) { objReference.SetActive(false); } Then you need a script with static variables public static bool turnObject1Off` on a script in the first scene. use public void TurnOnObject1() { turnObject1Off = true; or something along those lines for a button to call that new function.

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

223 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

Related Questions

CHANGING SCENE AND MAKE A GAME OBJECT ACTIVE THERE 0 Answers

When going to a new scene, set gameObject position to its current co-ordinates. 1 Answer

How to navigate from a non-VR scene to a VR enabled scene within Android 2 Answers

Restarting a scene with SceneManager 1 Answer

Scene clones itself and switches continuously. 0 Answers


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