horiaci_drak/Assets/scripts/enemykiller.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2022-04-27 19:12:09 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemykiller : MonoBehaviour
{
// Start is called before the first frame update
public ParticleSystem part;
public List<ParticleCollisionEvent> collisionEvents;
void Start()
{
part = GetComponent<ParticleSystem>();
collisionEvents = new List<ParticleCollisionEvent>();
}
// Update is called once per frame
void Update()
{
}
//on particle coolision
void OnParticleCollision(GameObject otherx)
{
int numCollisionEvents = part.GetCollisionEvents(otherx, collisionEvents);
int i = 0;
while (i < numCollisionEvents)
{
GameObject other = collisionEvents[i].colliderComponent.gameObject;
if (other.tag == "enemy")
{
Destroy(other);
Debug.Log("enemy killed");
}
if (other.tag == "king")
{
Destroy(other);
Debug.Log("killed king");
}
i++;
}
}
}