Unknown Identifier

can someone tell me why when i ask unity to tell me what is damage (Debug.Log (damage):wink: it says it is a unknown identifier. I showed damaged 100 % correctly, i said it was a float and what it is. maybe it is the debug command. and also when i state the debug command for another variable it doesnt even say anything about it, like it has ignored it

var baseDamage : int = 40;
var critChanceMax : float = 13;
var critChanceMin : float = 10;
var extraDamage : float;

function Start() {
Attack();
}

function Attack() {
var critDamage : float = Random.Range(critChanceMax, critChanceMin) / 10;
var damage : float = baseDamage * critDamage;
}
Debug.Log (damage);

A.) please format your code correctly. It makes it much easier for both you and us to see your mistakes.

B.) the problem is that damage is a local variable defined within the scope of the Attack() function. But you’re trying to Log it from outside that function ( in fact, it looks like you’re trying to Debug.Log from outside any function). Move Debug.Log inside the curly brackets that define Attack().

put debug in {}

function Attack() { var critDamage : float = Random.Range(critChanceMax, critChanceMin) / 10; var damage : float = baseDamage * critDamage; Debug.Log (damage); }

because damage is local variable !