Problem With Raycasts, Interaction Script.

Hello there.
I’m trying to make an interaction script.Everytime the ray hits the object with a certain tag it will run the object’s script named DoorInter.But everytime I try to ray an object, even if it’s not that i get the error

CameraRayRecongition.Update () (at
Assets/[Assets &

This is the Code :

var length : float = 100.0;
// Update is called once per frame
function Update () {
			var drawer : GameObject     = 	GameObject.FindWithTag("Drawer");
			var door   : GameObject 	= 	gameObject.FindWithTag("Door");
			var switches:GameObject		= 	GameObject.FindWithTag("Switches");
 			var ray : Ray =  Camera.main.ScreenPointToRay(Input.mousePosition);
 			var hit: RaycastHit;
 			var crosshairScript : CrossHair = GameObject.FindWithTag("MainCamera").GetComponent(CrossHair);
    Debug.DrawRay (ray.origin, ray.direction * length,;     
       if(Physics.Raycast (ray, hit,length)){
       var coll = hit.collider;

    if(coll == drawer.collider){
    //var inter : DoorInter = coll.GameObject.GetComponent(DoorInter);
   // inter.Dosomething();
     if(coll == door.collider){
   //  var inter2: DoorInter = coll.GameObject.GetComponent(DoorInter);
   // inter2.Dosomething();
      if(coll == switches.collider){
  /// var inter3 : DoorInter = coll.GameObject.GetComponent(DoorInter);
   // inter3.Dosomething();

Any ideas what should i do?

First off, “bumping post” is not really the way to go. Some forum would delete you for this kind of prctice (App Hub).

Now you need to understand the difference between GameObject and gameObject as I think this is where you are wrong.

var door   : GameObject  =   gameObject.FindWithTag("Door");

THis shoud not work as FindWithTag is a static function.

var inter : DoorInter = coll.GameObject.GetComponent(DoorInter);

This should be

var inter : DoorInter = coll.gameObject.GetComponent(DoorInter);

Using GameObject, you refer to the actual class. You use this for static methods like FindWithTag.

gameObject is used for instance methods like GetComponent

So when you want to do something that is inherent to the object use gameObject. If you want to do something general like finding an object in the scene, use GameObject.