Quantcast
Channel: Questions in topic: "finding"
Viewing all articles
Browse latest Browse all 73

How do I get closest particle?

$
0
0
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

Viewing all articles
Browse latest Browse all 73

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>