- Home /
Bullet Interaction
I'm creating a sidescrolling shmup (galaga basically.) but the bullets won't interact with the enemy.
here's the script for the enemy. I set the bullet tag to "Shot" and the script on the bullet just moves it.
using UnityEngine;
public class EnemyController : MonoBehaviour {
public float moveSpeed;
private Vector3 enemyPosition;
public int enemyHealth;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
enemyPosition = gameObject.transform.position;
gameObject.transform.position = new Vector3 (enemyPosition.x - moveSpeed, enemyPosition.y, 0f);
if (enemyHealth <= 0) {
Destroy (gameObject);
}
}
void OnTriggerCollide2D(Collider2D other){
if (other.tag == "Shot") {
enemyHealth = enemyHealth - 1;
// Destroy (gameObject);
}
}
}
any idea why it's not working?
Is OnTriggerCollide2D even a thing? I've seen OnTriggerEnter2D and OnCollisionEnter, but never OnTriggerCollide. Then again, I've only been messing with this stuff for about a month.
Answer by crawniik · Jun 13, 2018 at 06:56 PM
Try OnTriggerEnter2D. I don't think what you're using even exists.
My brain isn't working well enough at the present time to know which object needs to be set to Is Trigger, but one of them should need that. @DustyShadow
Answer by DustyShadow · Jun 13, 2018 at 10:52 PM
no, the script here is applied to the enemy. the script on the bullet simply moves it.