Michelle Menard book "unexpected token true" why???

Has anyone tried the Michelle Menard Game Development with Unity book?

The first script I’ve tried is buggy and I can’t figure if I’ve done something wrong or why I’m getting this error: “Unexpected token : true” for the variable: “private var outsideRange : true;”

Also the public variables aren’t showing up in the Inspector so I can’t assign the prefab.
Here is the script, if anyone can tell me if it’s me or Michelle that would be great! Thanks.

#pragma strict

//attach to a GameObject to serve as respawn point when the player walks within range

var spawnRange = 40.0;
var enemy : GameObject;

private var target : Transform;
private var currentEnemy : GameObject;
private var outsideRange : true;
private var distanceToPlayer;

function Start ()
{
target = GameObject.FindWithTag(“Player”).transform;
}

function Update ()
{
distanceToPlayer = transform.position - target.position;

if (distanceToPlayer.magnitude < spawnRange)
{
if (!currentEnemy)
{
currentEnemy = Instantiate(enemy, transform.position, transform.rotation);
}
}
else
{
if (currentEnemy)
Destroy(currentEnemy);
}
outsideRange = true;
}

@script AddComponentMenu (“Enemies/Respawn Point”)

you cant write private var variableName : true;

the " : " means you want to define the type, like boolean, vector3, float or similar. Try it like this:

private var outsideRange = true;

because you added true, the compiler will know it’s a boolean and set it to true.

Thank you, thank you! That makes sense!

But now I’m getting the console error: ‘magnitude’ is not a member of ‘Object’ for the first “if”. And the public variables still aren’t showing in the Inspector.
Thank you for getting back to me so fast!

magnitude isnt a member of the object class. magnitude is used for vectors. You DID say later on that distanceToPlayer is a vector, but you should add it to the declaration as well.

change:
private var distanceToPlayer;
to
private var distanceToPlayer : Vector3;

Not me! Michelle! I take full responsibility for the : = typo but this bit wasn’t me. Thank you so, SO much, you are a total star!

My enemies are spawning!
Which in any other context would be a worry but here it’s cause for joy!
Thank you!