Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

I'm finding closest with GameObject.FindGameObjectsWithTag("Enemy"). How can I use this code (or anything else) to find nearest enemy game object in multiplayer (unet)?

$
0
0
I'm finding closest with GameObject.FindGameObjectsWithTag("Enemy"). How can I use this code (or anything else) to find nearest enemy game object in multiplayer (unet)? I am actually making an rts game? Your help would be appreciated as I am new to the multiplayer game. Thank you. // Find the name of the closest enemy 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; } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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