I have a class where i store my variables that are public to all other functions. But the problem is that, it works when i test it in the unity editor, when i export it as web based application doesn’t work. After i search i found that the static variables are not updated.
Scenario: I have stored an variable in GenerealFunctions.cs which will be accessed from many other codes.
Example: When i call the method makeTrue() of the class aCode.cs with a UI button the variable theObject of the GeneralFunction.cs should be “true”. After that when i clicked up on a cube, or any other object where is attached the bcode.cs it should make should pass through the id statement (line 7) of the bCode.cs. This works when i test it in the unity platform, but when i export it as Web Player, doesn’t work.
GeneralFunctions.cs
using UnityEngine;
using System.Collections;
using System.IO;
public class GeneralFunctions {
static public bool newObject = false;
}
aCode.cs
using UnityEngine;
using System.Collections;
public class aCode : MonoBehaviour {
public void makeTrue(){
GeneralFunctions.newObject = true;
}
}
bCode .cs
using UnityEngine;
using System.Collections;
public class bCode : MonoBehaviour {
void OnMouseUp() {
if(GeneralFunctions.newObject){
print("make something");
GeneralFunctions.newObject = false;
}
}
}
I just did a quick test and did not run into any issues; here is what I did:
public class StaticClass
{
public static bool Value = false;
}
[ExecuteInEditMode]
public class Test : MonoBehaviour
{
[SerializeField]
private Vector2 position;
private void OnGUI( )
{
// Toggle value when button is clicked
if(GUI.Button(new Rect(position.x, position.y, 100, 30), StaticClass.Value.ToString()))
{
StaticClass.Value = !StaticClass.Value;
}
}
}
I attached this to a sprite to test the OnMouseUp function
public class Test2 : MonoBehaviour
{
private void OnMouseUp()
{
// Toggle value
StaticClass.Value = !StaticClass.Value;
}
}
Perhaps the problem could be that the object is not registering your clicks correctly. I would check the collider to make sure that it is capturing your mouse clicks
Your issue isn’t at all related to “static” variables not being updated. Generally check the log file before searching for the cause of a bug. That can cut down the time to find them significantly.
for the error of the 53 to 59 i have made a small change to code in order to found the error, now i correct it. but still have the same problem of non updating the static variable