Access to script global var's from a transform object? (specific ? on something that should work)

New to Unity.... My problem seems a bit different from other posts on acccessing script variables.

I have code below in a script.

The line 'badGuy.Enemy1_AI.EnemyLevel = badEnemyLevel;' fails with 'Enemy1_AI is not member of unity.transform'.

I am missing something, how can I correct this?


// GameMaster.js

var enemy1 : Transform; var badGuy : Transform;

var badEnemyLevel : int =1;

badGuy = Instantiate ( enemy1, Vector3 ( (Random.value * 400) - 200, 0, -2460), Quaternion.identity);

badGuy.Enemy1_AI.EnemyLevel = badEnemyLevel;


// Enemy1_AI.js

static var EnemyLevel : int;


What are you trying to achieve?

badGuy.Enemy1_AI.EnemyLevel = badEnemyLevel;

must fail as badGuy is of the type Transform. Transform however does not have a member .Enemy1_AI.EnemyLevel and therefore the compiler complaints.

I think this is what you're looking for

badGuy.gameObject.GetComponent(Enemy1_AI).EnemyLevel = badEnemyLevel;