I’m making a 2D game where a few attacks need the ability to travel through multiple enemies, but no matter how i seem to try to set up the colliders and rigid body, it always stops at the first enemy hit.
thanks In advance!
I’m making a 2D game where a few attacks need the ability to travel through multiple enemies, but no matter how i seem to try to set up the colliders and rigid body, it always stops at the first enemy hit.
thanks In advance!
Use this.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform bulletPrefab;
public Transform[] enemyObjects; //put all your enemy objects in here
void Update() {
foreach (Transform enemy in enemyObjects)
{
Transform bullet = Instantiate(bulletPrefab) as Transform;
Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), enemy.GetComponent <Collider2D>());
}
}
}
It’s not the best, but it’s all I can do and much more efficient than setting it to trigger
Use this.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform bulletPrefab;
public Transform[] enemyObjects; //put all your enemy objects in here
void Update() {
foreach (Transform enemy in enemyObjects)
{
Transform bullet = Instantiate(bulletPrefab) as Transform;
Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), enemy.GetComponent <Collider2D>());
}
}
}
It’s not the best, but it’s all I can do and much more efficient than setting it to trigger