the key that I put on my hashtable is an incrementing x, five iterations, and the value for each key is the hit.point.x when I’m raycasting.
I wanted to print each key and value in the console, but it doesn’t work.
you may take a look at that part of my code.
Rect rect = new Rect(10, 10, 120, 30);
if (GUI.Button(rect, "Raycast"))
{
Random.seed = 1234;
for (int x = 0; x < 5; x++)
{
RayCasting();
hashX.Add(x, arrayListX[x]);
foreach(object key in hashX.Keys)
{
print("Hashkey: " + key + " Hashvalue: " + hashX.Values);
}
}
}
the arrayListX[ ] is the arrayList where I put my hit.point.x(which is a random float) after every raycast.
What doesn’t work exactly? Does it print the key correctly now? Because that part seems ok. It’s just that you still use the array Values instead of it’s contents. You cannot really use foreach to iterate over two arrays like this. To iterate over both, try:
Also, why are you using a hashtable? ‘x’ is an int ranging from 0 to 5, so you might as well use arrayListX directly. Hashtables are meant for arrays that cannot use 0-n integers as index.
This code should work (i compiled and tested it in the Start() of an otherwise empty monoBehaviour), but if it doesn’t, there is something seriously wrong in your Mono build.
However, I believe it’s most likely something is wrong somewhere else in your code (i.e. somewhere beyond the hashtable code you pasted in this thread).