There is one object, it has a script with public values. There is another object, a script on it, which should take some variables from the first one and output them.

Now it looks like this

void Start() { AxisX = GameObject.FindGameObjectWithTag("Joystick").GetComponent<FloatSpeedXYJoystick>().AxisX; } private void OnGUI() { GUI.Label(new Rect(0, 0, 300, 30), "AxisX = " + AxisX.ToString("F3"); } 

It gets the values ​​at the start, but they are zero. Probably, the fact is that he gets them once?

But to set the Update function with FindGameObject and GetComponent in the Update is very demanding.

What is a simpler solution to get changing values ​​from a script of another object?

    1 answer 1

    To make a link in the second script not to the AxisX field (most likely it is not a reference type!?), But to the component.

      // Назначить в редакторе. public FloatSpeedXYJoystick _AxisX; void Start() { // Или найти тут. if(_AxisX == null) _AxisX = GameObject.FindGameObjectWithTag("Joystick"). GetComponent<FloatSpeedXYJoystick>() } private void OnGUI() { GUI.Label(new Rect(0, 0, 300, 30), "AxisX = " + _AxisX.AxisX .ToString("F3"); } 
    • FloatSpeedXYJoystick is a script. What kind of _Axis variable should be to access the script? I do not know the variables of the type Class or Script in Unity. - Dmitrii
    • one
      @Dmitrii, I already wrote in the answer. A script is a class (type). - Valera Kvip