У меня есть объект и на нём прикреплён такой скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTrigger : MonoBehaviour
{
[SerializeField] private EnemyMove enemyMove;
[SerializeField] private GameObject deathEffect;
[SerializeField] private GameObject damageEffect;
[SerializeField] private GameObject pointEffect;
[SerializeField] private GameObject damageSound;
[SerializeField] private GameObject pointSound;
[SerializeField] private float timeBeforeDeath;
[SerializeField] private int damage;
private PlayerController player;
private TextManager textManager;
private bool isCollision = false;
private void Start()
{
textManager = FindObjectOfType<TextManager>();
player = FindObjectOfType<PlayerController>();
}
private void OnTriggerExit2D(Collider2D collision)
{
if(collision.CompareTag("Enemy"))
Invoke("Death", timeBeforeDeath);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Point"))
{
isCollision = true;
Instantiate(pointEffect, transform.position, Quaternion.identity);
Instantiate(pointSound, transform.position, Quaternion.identity);
textManager.point++;
Destroy(gameObject, 0.01f);
}
if (collision.CompareTag("Player") && isCollision == false)
CollisionFunc();
if (collision.CompareTag("Enemy") && isCollision == false)
CollisionFunc();
}
private void CollisionFunc()
{
Instantiate(damageEffect, transform.position, Quaternion.identity);
Instantiate(damageSound, transform.position, Quaternion.identity);
player.TakeDamage(damage);
enemyMove.speed = 0f;
transform.parent = player.transform;
}
private void Death()
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
Instantiate(pointSound, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
И вот именно
Instantiate(pointEffect, transform.position, Quaternion.identity);
Instantiate(damageEffect, transform.position, Quaternion.identity);
Instantiate(deathEffect, transform.position, Quaternion.identity);
Вызываются не всегда, почему?