Access to method in other Script BUT.....

Hi, I want to access to one method in other script but:

Script A : MONOBEHAVIOUR
-use method from Scrip tB

Script B (NO MONOBEHAVIOUR)
-method();

The problem that I have is that if I create one object of the Script B in the Script A im getting one error like “GetComponent requires that the requested component “Script B” derives from Monobehaviour or Component or is an interface”.

And If i want to use the object of the Monobehaviour in the Script B Im getting the error:
“Null reference Object”

Basically im trying to use the PLAYERs position (inside of script A) as a parameter of the method of the ScriptB,

Thanks

pass the transform as a parameter

how/where is “scriptB”?

If B isn’t a MonoBehaviour, you have to create it like a normal class:

B b = new B();

It’s not a Component, so GetComponent() can’t work.

1 Like

Make the method on script ‘B’ static.

public static void SomeMethod(Vector3 position) { }

Then you can just call it like:

ScriptB.SomeMethod(playerPosition);

Thank you guys.

I solved it creating other static transfom variable in Script A and asigning the value of Player.transform. Then accessing to that vvalue like. ScriptA.staticTransformcreated

Thanks.

ok, so what happens if you have two gameobjects with scriptA on them… the static var can only have one value…