Что делать если не работает Collision2D?

вот скрипт 1 обьекта
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour
{
   
    public int health = 2;
    
    public GameObject boom;
   
    public int damage = 1;
    void Start()
    {
        boom = GameObject.Find("Boom");
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        
        if (collider.gameObject.tag == "Bullet")
        {
            GetComponent<AudioSource>().Play();
            health = health - 1;

        }
        if (health <= 0)
        {
            GameObject.Find("EnemySpawn").GetComponent<GameController>().KilledEnemy();
            
            boom.transform.position = new Vector2(transform.position.x, transform.position.y);
            boom.GetComponent<ParticleSystem>().Play();
            boom.GetComponent<AudioSource>().Play();
            Destroy(gameObject);

        }
    }
}

и второй скрипт
using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour
{

   
    public float lifetime = 2.0f;

    
    public float speed = 5.0f;

    
    public int damage = 1;

    // Use this for initialization
    void Start()
    {
        
        Destroy(gameObject, lifetime);
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.up * Time.deltaTime * speed);
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        
        if (collider.gameObject.tag == "Enemy")
        {
            Destroy(gameObject);

        }
        
    }
}

и что не так?
5c8ddcc4f4055689820494.png5c8ddd4bb35b4179839084.png
  • Вопрос задан
  • 86 просмотров
Решения вопроса 1
@Sir_Akakii
Для срабатывания триггеров, необходимо чтобы один из этих объектов имел компонент Rigidbody2D
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы