Hello, I am currently working on a small project and I am currently stuck as I don't know how to find closest particle. The thing I want to achive here is that enemies will dodge the particles (bullets). I have already found this ([source][1]) :
// Find the name of the closest enemy
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject FindClosestEnemy()
{
GameObject[] gos;
gos = GameObject.FindGameObjectsWithTag("Enemy");
GameObject closest = null;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
foreach (GameObject go in gos)
{
Vector3 diff = go.transform.position - position;
float curDistance = diff.sqrMagnitude;
if (curDistance < distance)
{
closest = go;
distance = curDistance;
}
}
return closest;
}
}
but I have no idea how to make it work with particles.
Thank you for all answers and ideas :) .
[1]: https://answers.unity.com/questions/64115/how-to-find-the-closest-object-marked-with-a-speci.html
↧