Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Virtual_TUe · Mar 09, 2021 at 05:56 PM · uiinspectorscene-switchingintpublic variable

public int variable not updated in inspector for two scenes in Unity

I have five scenes in my Unity Project/Game. The first one is start scene (Build Index = 0) and remaining four are the levels of the game as (1,2,3,4). The logic is such that when the user moves from one scene to the next one, a new scene appears and previous scene is removed from the list. The order in which scenes appear is randomized. I did this by using a Singleton. This works perfectly fine. What I also want to do is, when a new scene is loaded the public int advancement = 8; checks for the current scene. For example, when I press play and the run project starting from Scene 0, in the Inspector I see advancement = 8;. I press button to load next scene. A new scene (lets say Scene 2) is loaded and in inspector I see advancement = 4; as I proceed in the game the advancement decreases as 3, 2, 1. This C# code works fine on my laptop. However, when I copied the the script in a different Unity Project on a different laptop. The code is working only for two scenes i.e., Scenes with Build Index 1 and 3. For Scenes with Build Index 2 and 4 the public variable advancement = 8 in the inspector and is never updated.

Can someone help me troubleshoot this?

Please see the code below.

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System;
 
 public class BRIRToMax : MonoBehaviour {
 
     private static int localPort;
     private string IP;  // define in init
     public int port = 8051;  // define in init
     public int advancement = 8;
     
 
     // "connection" things
     IPEndPoint remoteEndPoint;
     UdpClient client;
 
     void Start()
     {
         
       IP = "127.0.0.1";
       port = 8051;
 
       remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP), port);
       client = new UdpClient();
 
       int currentSceneBuildIndex = SceneManager.GetActiveScene().buildIndex;
       SendCurrentSceneBuildIndexToMaxMSP(currentSceneBuildIndex);
      
 
     }
 
     public void SendCurrentSceneBuildIndexToMaxMSP(int buildIndex)
     {
         // The UDP stuff to send to MaxMSP
         byte[] data1;
         Debug.Log("Build Index =:" +buildIndex);
 
   
         
         if (GameObject.Find("ButtonNextScene"))
         {
             
             Debug.Log("Remaining Scenes = " + (SceneAdvance.instance.remainingScenes-1));
             advancement = SceneAdvance.instance.remainingScenes;
      
         }
     
         try
         {
             if (advancement == 3) 
             {    
                 
                 byte[] welcome = Encoding.ASCII.GetBytes("H");
                 client.Send(welcome, welcome.Length, remoteEndPoint);
             } 
             
             else 
 
             {
 
                 Debug.Log("Do not trigger the toggle");
 
             
             }
 
             switch (buildIndex)
             {
                
                 case 1:
                     data1 = Encoding.ASCII.GetBytes("Q"); //Sc2_3500
                     client.Send(data1, data1.Length, remoteEndPoint);
                     Debug.Log("Q");
                     break;
 
                 case 2:
                     data1 = Encoding.ASCII.GetBytes("W"); //Sc2_1500
                     client.Send(data1, data1.Length, remoteEndPoint);
                     Debug.Log("W");
                     break;
 
                 case 3:
                     data1 = Encoding.ASCII.GetBytes("E");//Sc1_3500
                     client.Send(data1, data1.Length, remoteEndPoint);
                     Debug.Log("E");
                     break;
 
                 case 4:
                     data1 = Encoding.ASCII.GetBytes("R");//Sc1_1500
                     client.Send(data1, data1.Length, remoteEndPoint);
                     Debug.Log("R");
                     break;
             }
         }
         catch (Exception err)
         {
            Debug.Log(err.ToString());
         }
 
     }
 
 }


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

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

246 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

Related Questions

Object looses Inspector properties When Scene returns 1 Answer

How do I bind the value of a public variable from the inspector to some other variable/constant? 0 Answers

Custom UnityEngine.UI button inspector 1 Answer

Help! with the Message text 0 Answers

Public Variables Not Displaying In The Inspector 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