UnassignedReferenceException: What did i do Wrong?

The code works and everything goes according to plan.

except I keep getting the error

UnassignedReferenceException: The variable Barrel of ‘Turret_Lock’ has not been assigned.

But te varriable is assigned in the inspector.

the script is for a turret who can “lock” on the player.


var target : Transform;
var Barrel: Transform;
var BarrelEnd: Transform;

var TurnSpeed: int= 5;
var AttRng: float = 6;

function Start(){

	var lol: CapsuleCollider;
	lol= gameObject.GetComponent(CapsuleCollider);
	lol= gameObject.collider;
	lol.radius= AttRng;

function Update () {


function OnTriggerEnter(Other: Collider){

	if(Other.collider.tag == "Player"){
		target= Other.collider.transform;


function OnTriggerExit(){
	target= null;

function Target(){
 	var rotation: Quaternion;
        var relativePos = target.position - Barrel.transform.position;
    	rotation = Quaternion.LookRotation(Vector3.Slerp(Barrel.transform.position,relativePos,2*Time.time));
    if(target== null){
    rotation = Quaternion.identity;

// something is wrong here according to Unity 

      Barrel.transform.rotation= Quaternion.Lerp(Barrel.transform.rotation, rotation, Time.deltaTime*TurnSpeed);


Anyone an Idea ?

Barrel is never assigned as an instance of a transform, either is BarrelEnd. They can be assigned through the inspector by making the variables public:

public var Barrel: Transform;
public var BarrelEnd: Transform;

This script can be attached to either Barrel or BarrelEnd, not both.