I have code attached to a first person camera and a compiler error keeps appearing "unknown identifier" - enemy
var bulletDamage = 50;
var range = 5000;
var hit : RaycastHit;
Screen.showCursor = false;
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(transform.position, transform.forward, hit, range))
{
if(hit.collider.gameObject.tag == "enemy")
{
//print("HIT");
enemy.BroadcastMessage("OnHit");
}
}
}
}
The next bit is attached to the enemy prefab which is spawned on the screen when the player gets within a certain range.
static var AIHEALTH = 100;
function Awake()
{
gameObject.tag = "enemy";
}
function OnHit()
{
if(AIHEALTH <= 0)
{
KillObject();
}
else
{
AIHEALTH -=50;
}
}
function KillObject()
{
Destroy(gameObject);
}
any help would be great, thanks.
That means you need to add the tag to the tag manager
– anon85704231