- Home /
front check based on unity projects not working.
Before updating to unity 4.5 I was using a code with a front check to check when my player has an enemy in front of him and a trigger collider for when it hits him he can explode. My problem is that it worked for when it was in 4.3 but now in 4.5 it seems to contradict it other with the trigger for when it hits being used. Is there a work around for this? Here's my code:
For trigger: void OnTriggerEnter2D (Collider2D bbcol){
// If it hits an enemy...
if (bbcol.tag == "Enemy") {
if (enemyhit == false){
bbcol.gameObject.GetComponent<Bugbot> ().RemoveHp ();
HP -= 2;
enemyhit = true;
}
}
Here's my front check:
foreach (Collider2D c in frontHits) {
// If any of the colliders is an Obstacle...
if (c.tag == "DirectionTrigger") {
// ... Flip the enemy and stop checking the other colliders.
Flip ();
break;
}
if (c.tag == "Enemy") {
if (enemyhit == false){
if (c.gameObject.GetComponent<Bugbot> ().destructionImminent == false)
{
// ... Flip the enemy and stop checking the other colliders.
animator.SetTrigger("swat");
walking = false;
if (!muted)
{
if(!SFXstatus && !audio.isPlaying)
{
clip1.Play();
}
else if (SFXstatus && audio.isPlaying)
{
clip1.Stop ();
}
}
else if (muted)
{
clip1.Stop ();
}
}
}
break;
}
}
Comment