Answer the question
In order to leave comments, you need to log in
Why doesn't CompareTag work?
Hello. I'm trying to make the character take damage from poking into the spikes, he takes damage twice, because there are 2 colliders on him for different purposes, I marked the character's hitbox with the "Player" tag, and the hitbox of the spikes with the "Spike" tag, but I have CompareTag doesn't work, what am I doing wrong?
Here is the code:
private float health = 10f;
private void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("Spike") && gameObject.CompareTag("Player")) {
StartCoroutine(SpikeDMG());
}
if(health <= 0)
Destroy(gameObject);
}
IEnumerator SpikeDMG() {
health -= 5f;
yield return new WaitForSeconds(0.1f);
}
Answer the question
In order to leave comments, you need to log in
you can make a separate empty object on the player, which will contain, in your words, a collider for collisions, and throw a script on this dummy that tracks the touch of the spikes. As a result, only 1 collider will be read, and not as you had 2. You will only have to link 2 scripts (well, the player and the script for responding to the spikes so that when the player gets up on the spike, the damage method is called)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question