I am having many problems trying to change variables on script components on other objects under pragma strict. this is a script that works on an android tablet i want to be abel to change the settings on the ‘DragOrbit.cs’ script attached to the main camera.
var camOverview: GameObject; // main camera assigned to this variable
if(GUI.Button(Rect(10,10,150,50), "Cam orbit change")){
var dragorbit : MonoBehaviour = camOverview.GetComponent("DragOrbit") as MonoBehaviour;
dragorbit.enabled = !tbddragorbit.enabled; //switches script on and off
Debug.Log(tbddragorbit.); // returns Main Camera (DragOrbit)
}
this script works and manages to switch the script off and on but i cant get it to access the target or distance variables which are in the dragorbit script by using
dragorbit.target = 60;
i get an error message saying
'target' is not a member of 'UnityEngine.MonoBehaviour'
i have tried to set the type of the component variable to itself
var dragorbit : DragOrbit = camOverview.GetComponent("DragOrbit") as DragOrbit;
but then i get this error
BCE0018: The name 'DragOrbit' does not denote a valid type ('not found').
Would really appreciate any help on this.
I notice your DragOrbit is Csharp and this script is JavaScript. With the BCE0018 error, it looks like a compilation order problem to me. Are both scripts in the same folder? Are they in the Plugins or Standard Assets folder?
– by0log1ci dont think its compilation order but a type error - i can only GetComponent as a monobehaviour i cannot set the getcomponent class as the script class. i have tried to put both scripts in seperate and plugin folders but it still doesn't work
– anon84960534A type error is returned, yes, but only because the compilation order have your JavaScript unable to read your CSharp class. Putting your CSharp in the Plugins have them compiled earlier (ready for JavaScript). With that done, you may finally cast your variable as a DragOrbit type and access whatever property you need. That's why mixing programming languages can ruin your day.
– by0log1cThats done it BY0LOG1C I understand it now and it works. THANKS! Could you post that as an answer so i can mark it as answered.
– anon84960534