W
W
WasTabon2020-09-28 20:48:39
Unity
WasTabon, 2020-09-28 20:48:39

Why does the contact of colliders in one object work, but not in another?

Here it does not work, although if you change the tag to Wall, it works

void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.tag == "EnergyDrink") // Проверка на столкновение с энергетиком
        {
            Debug.Log(123);
            Destroy(col.gameObject); // Энергетик уничтожается 
            EnergyNumber  += PlusEnergy; // Добавляется энергия
        }
    }


5f72215771246696091328.png

But here it works, because of what this can be?

void OnCollisionEnter(Collision col)
        {
            if (col.gameObject.tag == "Wall") // Проверка на столкновение со стеной
            {
                if (Energy < 5) // Пока что пусть будет 5, потом поменяем
                {
                    PlayCamera.SetActive(false);
                    UICamera.SetActive(true);
                    DeathPanel.SetActive(true); // Вызывание панельки смерти
                }
            }
        }


5f7221f6270ef889025628.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2020-09-28
@WasTabon

And, I already decided, you just need to add Rigidbody

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question