How to access a non static variable by another static variable?

Hello,

I wish to use a value in say B script. Now in A script I have a variable is modified using GUI in run time. I wish to use that same variable in another script in run time i.e. changes in GUI should affect both the variables.

Code :

var canonPrefab : Transform;

var velocity = 10.0f ;

var angle : float = 20.0f;

//Global variables

static var g_angle : float = angled;

static var g_velocity :float = velocity;

Could someone help me with this?

Thank you very much in advance.

If the above script is defined in a file named CannonController.js, you could refer to it in another script like this:

filename: SomeOtherScript.js

public  var cannonScript  :  CannonController;

function Update ()
{
    if ( cannonScript == null ) {
        Debug.Log("Please assign CannonController object");
        return;
    }

    Debug.Log("Cannon Script velocity: " + cannonScript.velocity);
}

When you define a public variable named cannonScript of type CannonController you can assign any object with a CannonController script attached to it in the Inspector.

You can do that like this:

  • select an object with a SomeOtherScript attached to it by left-clicking it
  • look in the Inspector for a slot named Cannon Script
  • drag any object with a CannonController script attached to it onto this slot

I'm not sure why you have those static variables. Perhaps you could explain that.