Quantcast
Viewing latest article 4
Browse Latest Browse All 64

Finding a value in a List

I need to find a value in a List. This is an example code that shows what I would want to do. private List spaces; private gridSize = 2.5; public struct Space{ public Vector3 coor; public Vector3 pos; public int color; public bool isCircle; public Space(Vector3 c, Vector3 p, int cr, bool ic){ coor = c; pos = p; color = cr; isCircle = ic; } } private static void CreateList(){ spaces = new List(); for(int x = 0; x < 10; x++){ for(int x = 0; x < 10; x++){ for(int x = 0; x < 10; x++){ coorToPos(new Vector3(x, y, z)) } } } } private Vector3 coorToPos(Vector3 cor){ Vector3 newPos = new Vector3(cor.x * gridSize, cor.y * gridSize, cor.z * gridSize) return newPos } So, in detail, what I really want to do is... I want to create a function so if I plug in the coordinate or the position of a point in the list, I would be able to get the color, and isCircle Boolean. I know a foreach funtion will do this by: private Space FindTheSpace(Vector3 vectorCheck, isPos){ foreach(spacs in Space){ if(!isPos && spcs.coor == vectorCheck) return spcs; else if(isPos && spcs.pos == vectorCheck) return spcs; else return null; } } However, I don't really want to use an foreach funtion because this is going to be in a foreach funtion. I really don't want it to be a double foreach function because I think it will lag too much.... So anyways, I hope you understood my question. If you did not understand something, please ask me. Thank you for your time and effort to trying to solve this problem I have Thanks

Viewing latest article 4
Browse Latest Browse All 64

Trending Articles



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