- Home /
GetComponent(Script) Error(Won't detect script)
Here is a javascript I have for a camera handler:
#pragma strict
var cockpitCamera : GameObject;
var orbitCamera : GameObject;
var orbitCameraObject : GameObject;
function Start () {
cockpitCamera.camera.active = true;
}
function FixedUpdate () {
var cameraInput : float = Input.GetAxis("Change Camera");
var rotateScript = orbitCameraObject.GetComponent(ArcBall);
//toggle between the two cameras
if(cameraInput != 0){
cockpitCamera.camera.active = !cockpitCamera.camera.active;
orbitCamera.camera.active = !orbitCamera.camera.active;
rotateScript.enabled = !rotateScript.enabled;
}
}
For some reason it won't recognize ArcBall as a name of a script I have written, and I don't know why. Do I have to create an instance of ArcBall or something?
Can you include the exact error you get and make sure the ArcBall script is attached to orbitCameraObject.
Edit: as @getyour411 says, if the ArcBall script is written in C# you need to use quotes.
@T27$$anonymous$$:
If it's written in C#, the C# script just need to be placed into the plugins folder. If you don't put it in a higher compilation group then you can use the "string version" of GetComponent, but in this case you can't access class specific variables or methods of the class. You just get a Component reference which doesn't even have an enabled property. The best you can cast such a reference to is $$anonymous$$onoBehaviour so you have at least the enabled property. You can't get more concrete since the actual class doesn't exist from the UnityScript's point of view.
Your answer
Follow this Question
Related Questions
error with footsteps script 1 Answer
Ending my game 3 Answers
Why is this player script not working 1 Answer
Operator '*' cannot be used with a left hand side ....... 1 Answer
Debug.Log error 2 Answers