- Home /
Cannot access another script's Vector3?
I have a Vector3 on a script (Script A) called currentPlatformPosition. I then have a function on Script B that says "if (isCurrentPlatform == true)", then I want to access currentPlatformPosition on script a and change it to a Vector3 on script B called myPosition. What Is the easiest way to do do that? I keep getting parsing errors. I thought I could do that with just "clickManager.GetComponent<"ScriptA">().currentPlatformPosition = myPosition;"
Please help
Answer by JVene · Jul 10, 2018 at 04:40 AM
A bit more exact example of your code would be helpful, and something of the verbiage the compiler is complaining with, to better understand what you mean by parsing errors.
However, I do see that the quotes inside the should not be there. That should be a type, not a name.
You may do well, in order to keep things more easily identifiable for debugging the compile errors, to separate these steps. That is,
ScriptA s = clickManager.GetComponent<ScriptA>();
Then,
s.currentPlatformPosition = myPosition;
That also gives you the chance to know if GetComponent actually did give you a ScriptA - if it returned a null because clickManager was not the actual owner of the ScriptA, your version would throw an exception trying to assign the .currentPlatformPosition to a non-extant object.
This means it's not a bad idea to check, before you use "s", with something like
if ( s != null ) {...}
Your answer
![](https://koobas.hobune.stream/wayback/20220612170401im_/https://answers.unity.com/themes/thub/images/avi.jpg)