My enemy is tagged “enemy”. And i want to have my spotlight flicker when seeing enemy. Is there any way to do this?
//Enemy script
function OnBecameVisible () {
Spotlight.Flicker();
}
//Spotlight script
static var spotlight : Light;
function Start () {
spotlight = GetComponent(Light);
}
static function Flicker () {
for (var i = 0; i<5; i++) {
spotlight.enabled=!spotlight.enabled;
yield WaitForSeconds(.05);
}
spotlight.enabled = true;
}