I have a HashSet, a List and a class.
Relayhash contains a set of Vector3 variables. Used as a list for input, usually one variable is picked either randomly or via another rule.
tempList To temporarily store vector3 variables for comparison.
BuildList contains a set of custom class types (moduleclass) and serves as the destination of selected variables.Here, I would like to find out if it contains a certain variable (posv3).
public class moduleClass
{
public int step { get; set; }
public int modID { get; set; }
public string modType { get; set; }
public int typeint { get; set; }
public Vector3 posv3 { get; set; }
}
I would like to find out if relayhash contains a Vector that is already in BuildList. If true, then the found Vector3(s) needs to be removed from ‘relayHash’. Then the values of the relayhash (Hashset) can be copied to the tempList (List) to enable random selection:
Vector3 randomV3 = tempList[Random.Range(0, relayhash.Count)];
The main issue is now that it’s not possible to remove a found Vector from the ‘relayhash’. For example:
var foundVectors = relayhash.Intersect(BuildList.Select(x => x.posv3));
relayhash.Remove(foundVectors);
results in:
error CS1503: Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<UnityEngine.Vector3>' to 'UnityEngine.Vector3'
So my question remains: how can I compare a vector3 between two lists- BuildList and relayhash- (one as a vector3 between custom datatypes and the other list vector3 only) and if a duplicate is found, remove it from the second list?
Alternatively, the script may select a random vector3 from the relayhash, and if not already in BuildList, add to it.
Thanks for reading.
ps I received helpful answers here but it didn’t work.