Acessing a variable from another script.

Hey! Ive been trying to acess and replace a value in a varaible from another script.
I do have a targetingsystem, when i target something selectedTarget gets a value, i want this value into my spells targets aswell. But they are in another script.

This is what i come up with:

In “Targeting”
SpellAI SpellsAffected = (SpellAI)GetComponent(“SpellAI”);
SpellsAffected.Target = selectedTarget.gameObject.transform;
What is the best way to acess, cause this wont work!
Should i try to acess it from SpellAI? Or?

TBH, I would just use static variables, I would use GetComponent for fetching a collider or a renderer.

Now I don’t know there are disadvantages/advantages performance wise over using static variable over using GetComponents though.

It’s covered in the docs: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html Also, you very rarely want to use quotes with GetComponent.

That’s a bad idea unless you know what static means and what it does.

–Eric

or you can just do Classes.

example :

public var otherScript : "Name of the Script"

function Update ()
{
     if (otherScript."Name of the var" == true)
     {
          do something
     }
}