Best way to send a value to another Script?

Hello,

how is the best way to send a value from script A to B in a constant update?

my script A its a player with float V and float H (input Axis)

my script B its a guiTexture with touch imput with float V and float H.

I need that my script A read only those 2 values from script B (V,H). not all the script.

I use : public static float H , V.
But i saw that using public static its not good at all. so i dont want to use it.

So, how should i do it? Getcomponent? GameObjectFind ? or maybe create 1 child class for 2 scripts, its that possible?

Thank you

GetComponent once, then track the changes. Static is “bad” unless you want a single variable being referenced in many scripts.
The variables you’re tracking should be public (default in UnityScript, necessary in C#).

Edit: To get a component, you’ll need to have a reference of the gameObject. You can accomplish this with a GameObject.Find() or GameObject.FindWithTag().

Hey, thank you

im doing this. idk if its OK.

Script A(player):

start(){
GameObject UIjoystiq;
joystiqScript joystiq;

joystiq = UIjoystiq.GetComponent<joystiqScript>();
}
update(){
Debug.Log(joystiq.touchH);
}

Then in script B (joystiqScript)
i changed the touchH to public touchH , not static.

it works… but can i only cache the script and skip the gameObject?

and also, can i keep the touchH private and use a getter only? (how i do that?)

You can access this script and pass the script you want as a parameter as well.

I don’t know how to do this in UnityScript, but in C# you’ll use something like this:

using UnityScript;
using System.Collections;

public class YourScript : MonoBehaviour {
      private int a;

      public int A {
          get { return a; }
          set { a = value; }
      }


}