Help with error: UnassignedReferenceException

Edit, I assigned references to both Flames, and the message keeps poping up.

alt text

This is the error:

UnassignedReferenceException: The variable leftFlame of 'TurretControl' has not been assigned.
You probably need to assign the leftFlame variable of the TurretControl script in the inspector.
TurretControl.Awake () (at Assets/Scripts/TurretControl.js:13)

This is the script:

//Turret control script

var target : Transform;
var range = 10.0;
var leftFlame : GameObject;
var rightFlame : GameObject;

static var mode = "idle";

function Awake()
{
    target = GameObject.FindWithTag("Player").transform;
    leftFlame.renderer.enabled = false;
    rightFlame.renderer.enabled = false;
}

function Update () 
{
    if(target && CanAttackTarget())
    {
        //transform.LookAt(target);
        var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 1.2);
    }
}

function CanAttackTarget()
{ 
    //check if the target is close enough
    if(Vector3.Distance(transform.position, target.position) > range)
    {
        Disengage();
        return false;
    }

    var hit : RaycastHit;

    //check if there is collision inbetween turrent and target
    if(Physics.Linecast(transform.position, target.position, hit))
    {
        if(hit.collider.gameObject.tag != "Player")
        {
            Disengage();
            return false;
        }
        else
        {
            Attack();
            return true;
        }
    }
    return true;
}

function Attack()
{
    if(mode != "attack")
    {
        InvokeRepeating("FalconAnimate", 2, 0.05);
        mode = "attack";
    }
}

function Disengage()
{
    if(mode != "idle")
    {
        CancelInvoke();
        mode = "idle";
        leftFlame.renderer.enabled = false;
        rightFlame.renderer.enabled = false;
    }
}

function FalconAnimate()
{
    if(leftFlame && rightFlame)
    {
        if(leftFlame.renderer.enabled)
        {
            leftFlame.renderer.enabled = false;
            rightFlame.renderer.enabled = true;
        }
        else
        {
            leftFlame.renderer.enabled = true;
            rightFlame.renderer.enabled = false;
        }
    }
    else
    {
        print("Effects on turrent not set!");
    }
}

I was having the same problem and this thread helped me out. But I would like to restate clearly my mistake so that it is clear for others:

I was dragging my prefab (from the project view) onto the inspector while having selected the script in the project view (which is wrong);

this looks like it works (the prefab name shows up in the variable slot) - but does nothing. I guess this was sort of like combining blueprints; instead, I dragged my prefab (again from the project view) onto the inspector while the instance of my script (in the scene hierarchy) was selected. Then all was good again :).

Did you do that, assign the leftFlame variable of the TurretControl script in the inspector?

Im doing this with a Tutorial, and the guy never assigned anything in the inspector from what I can tell.

had that problem too here is what i did. i included a new variable ‘x’
and assigned the false value in my function update and then changed its value so it doesnt update its value again.


var target : Transform;

var range = 10.0;

var leftFlame : GameObject;

var rightFlame : GameObject;

var mode = “idle”;

var x = “t”;

function Awake()

{

     target = GameObject.FindWithTag("Player").transform;

}

function Update ()

{

if( x ==“t”)

{

 leftFlame.renderer.enabled = false;

	 rightFlame.renderer.enabled = false;

	 x="s";

}

Should it be of help, I have just resolved my ‘UnassignedReferenceException’.
For those using the same book. To cut a long story short, the solution was that,
I have a bullet prefab, an explosion prefab and a moveBullet scipt.
The moveBullet script was changed to show the explosion prefab.
You will easily see the explosion variable displayed at the top of the inspector window and will have dragged and dropped the explosion prefab to the variable.
Now you will have to go back to the original bullet prefab find the same movebullet script in the inspector window for that prefab and add the explosion prefab to the script a second time.
N.B. I am a total beginner and the book is Holistic Game Development with Unity