Created
October 4, 2020 21:34
-
-
Save hugodahl/c536e83a3d5ab41d3d3ece2c68adf30c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start work from the list/collection/array of all "CurrentAmmoSpanPos", which are the spawners | |
var spawners = CurrentAmmoSpanPos.Select(spawner => // Create an "anonymous" type, which generates an object with properties | |
new { | |
// Save the spawner, so we can use it later | |
Spawner = spawner, | |
// Calculate the distance between the player in that | |
Distance = Vector3.Distance(Player.transform.position, spawner.position) | |
} | |
) | |
// Order all the items by position, smallest (closest) to biggest (furthest) | |
.OrderBy(pos => pos.Distance) | |
// Don't use the one in 1st place (closest) | |
.Skip(1) | |
// Take the next 3 | |
.Take(3) | |
// Make it a list. Array may be better? | |
.ToList(); // .ToArray() to make it an array | |
var pickedSpawnPos = spawners[RandomInt(0, spawners.Count)] // Get the random spawner between 1-3 (0-2) | |
.Spawner // Pick the spawner that we saved earlier. We could also see ".Distance" here | |
.position; // Get the ".position" property of the spawner, because it's what we need. | |
return pickedSpawnPos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment