Declare Component type in GetComponent


So I am trying to access scripts from a couple of other objects, and it is working fine in one case, but not in another, and i’m doing exactly the same thing!?!?

   private var cam : Camera;
private var player : Transform;
private var gyroScript : gyroCam;
private var tapScript : TapMoveDragLook;

function Start(){

cam = Camera.mainCamera;
gyroScript = cam.GetComponent(gyroCam);

player = transform.Find("Player");
tapScript = player.GetComponent(TapMoveDragLook);


The gyro related stuff works fine, but it says that ‘TapDragMoveLook’ does not denote a valid type, but gyroCam is a valid type either is it, how can one be and one not?

If i change the type to component I can access it it seems, but not enable/disable.

I’m stumped and would love some help!!

Thanks heaps.

There are only a few possibilities:

  • The other script is C# and therefore can’t be accessed by UnityScript unless it’s compiled first (so the c# script is in an earlier compilation group).
  • Both scripts are UnityScript (i guess they are after your reply) and you placed them in seperate compiling groups, so they can’t see each other.
  • The last thing would be you mistyped the name. The script name has to be exactly the same. It’s case-sensitive TapMoveDragLook would not be the same as TapMoveDraglook for example.

The compiling groups can be irritating when you don’t know about them. Read this page carefuly: script compilation groups.

TapMoveDragLook refers to your own custom class. If it’s not a valid type, then you may not have the class declared correctly.

public class TapMoveDragLook : MonoBehaviour {

Should be at the top of your file declaring this class.