I have two trap which are the same:
- a invisible trap that is on the enemy (child of the enemy), has a tag of ‘Ability’ (has RB2d, box collider but turned off)
- a trap ability so when the player hits the ability button, it shoot a trap prefab, has a tag of ‘Ability2’ (has rb2d and box collider turned on)
What I want:
- when trap ability is shot and collides with the invisible trap, spriteRenderer turns on (makes trap visible), box collider turns on, so when player shoots a projectile and it collides with the trap, enemy takes damage, spriteRenderer turns off (trap is invisible) and box collider turns off
What actually happens:
- when trap ability is shot, it ignores the invisible trap and hits and pushes the enemy which i dont want
invisible trap script:
public Enemy enemy;
public GameObject lightningTrap;
public Mouse refToShotCount;
private void Start()
{
refToShotCount = GameObject.Find("Mouse").GetComponent<Mouse>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Ability2")
{
print("collided");
lightningTrap.GetComponent<SpriteRenderer>().enabled = true;
lightningTrap.GetComponent<BoxCollider2D>().enabled = true;
Destroy(GameObject.FindGameObjectWithTag("Ability2"));
}
if (collision.gameObject.tag == "Projectile")
{
refToShotCount.shotCount++;
enemy.randomDamage = Random.Range(50, 76);
enemy.TakeDamage(enemy.randomDamage);
enemy.ShowDamageNumber();
lightningTrap.GetComponent<SpriteRenderer>().enabled = false;
lightningTrap.GetComponent<BoxCollider2D>().enabled = false;
Destroy(GameObject.FindGameObjectWithTag("Projectile"));
}
}
Thank You, it worked! usedByComposite gives me an error but I commented it out and it still worked
– jacksond02