So lets say its ObjectA and ObjectB. ObjectA has class MoveA attached to in, and ObjectB has class MoveB attached to it. In MoveA I run an OnTriggerEvent function, and find that ObjectB is colliding with ObjectA, so I want to grab a variable, lets say VelocityB, from ClassB to use in this MoveA class.
How would I pass it over?
Assuming that ObjectA/MoveA has some sort of reference or can find ObjectB/MoveB. (with GameObject.Find(“ObjectB”) etc.
C# Code for ObjectA/MoveA script.
// object reference
GameObject ObjectB = GameObject.Find(“ObjectB”);
MoveB scriptMoveB = ObjectB.GetComponent();
// access a variable
print(scriptMoveB.velocity);
// access a method
scriptMoveB.SomeFunction();
Its not just read only, you can update the variable in MoveB. Anything in MoveB class you want to access has to be Public.
This worked out great. Thanks.