Hi there,
May someone tell me what’s wrong in this code that doesn’t throw any error in the log but doesn’t work either.
As you can see, my player is supposed to detect “enemy” at start which allows the “didpunch” message to be sent upon screen tap. My enemies are stored in an array (6 of them) and get activated/deactivated sequentially.
Everything works except that I can’t fire as if “enemy” was not tracked. And again no error message.
I am learning how to use array so I am probably not using it properly.
thks for your help.
the js script
var punchSound : AudioClip;
var kangastrike : AudioClip;
private var busy = false;
var targets : GameObject[];
var boomerangprefab : GameObject;
var boomlongprefab : GameObject;
var boomiddleprefab : GameObject;
private var boomtrigger: GameObject;
private var gui : GUITexture;
function Start ()
{
targets = GameObject.FindGameObjectsWithTag("enemy");
boomtrigger = GameObject.Find("BoomTrigger");
}
function Update ()
{
for (var enemy in targets)
{
if(Application.platform == RuntimePlatform.IPhonePlayer)
{
for (var i = 0; i < iPhoneInput.touchCount; ++i) {
var touch : iPhoneTouch = iPhoneInput.GetTouch(i);
if(enemy !busy (touch.phase == iPhoneTouchPhase.Began))
{
SendMessage ("DidPunch");
busy = true;
}
}
}
else
{
if(enemy !busy Input.GetButtonDown ("Fire1"))
{
SendMessage ("DidPunch");
busy = true;
}
}
}
}
function DidPunch ()
{
var animationController : AnimationController = GetComponent( AnimationController );
for (var enemy in targets)
{
var targetpos = enemy.transform.position;
var distanceToTarget = Vector3.Distance(transform.position, targetpos);
if (distanceToTarget < 26)
{
animation.Blend("idle",0.0,0.1);
animationController.animationTarget.CrossFadeQueued("strike", 0.1, QueueMode.PlayNow);
yield WaitForSeconds(0.2);
audio.PlayOneShot(punchSound);
Instantiate(boomerangprefab,boomtrigger.transform.position,boomtrigger.transform.rotation);
busy = false;
}
else if (distanceToTarget < 45)
{
animation.Blend("idle",0.0,0.1);
animationController.animationTarget.CrossFadeQueued("strike", 0.1, QueueMode.PlayNow);
yield WaitForSeconds(0.2);
audio.PlayOneShot(punchSound);
Instantiate(boomiddleprefab,boomtrigger.transform.position,boomtrigger.transform.rotation);
busy = false;
}
else
{
animation.Blend("idle",0.0,0.1);
animationController.animationTarget.CrossFadeQueued("strike", 0.1, QueueMode.PlayNow);
yield WaitForSeconds(0.2);
audio.PlayOneShot(punchSound);
Instantiate(boomlongprefab,boomtrigger.transform.position,boomtrigger.transform.rotation);
busy = false;
}
}
}
function PlayerBusy ()
{
busy = true;
}
@script RequireComponent(AudioSource)