Home Access public static variable from another script Unity
Reply: 1

Access public static variable from another script Unity

Anh Minh Trần
Anh Minh Trần Published in 2017-12-07 21:59:42Z

I am trying to access and change of the value of a variable from another script, I have watched various different tutorial on youtube but cannot seems to do it. It always come up with an error as following:

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

public class GlobalValues : MonoBehaviour

    public static bool c2u;


And the other script

public class Choosing : MonoBehaviour {
private void Start()
    GlobalValues.c2u = false;

In the "Choosing" script, the GlobalValues always shows "'GlobalValues' does not exist in this current context". What can i do to fix this problem

SilentSin Reply to 2017-12-07 23:41:27Z

That code should work fine. The only way I could see it not working is if you haven't saved one of the scripts.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.354726 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO