list.contains problem
I'm trying to check if a list already contains a variable (which is an int) but it says "cannot convert 'int' expression to type 'maze list' " and i'm quite new to unity so i can't figure out whats wrong, here's the class:
using UnityEngine;
using System.Collections;
public class MazeList
{
public int roomPos;
public MazeList(int newRoomPos)
{
roomPos = newRoomPos;
}
}
And the code in question:
private int roomPosition;
private int direction;
private int roomSpawner;
List<MazeList> roomList = new List<MazeList> ();
// Use this for initialization
void Start ()
{
roomList.Clear ();
roomPosition = Random.Range (0, 16);
roomList.Add(new MazeList (roomPosition));
if (roomList.Count < 6) {
direction = Random.Range (0, 4);
if (direction == 1) {
roomPosition += 1;
if (roomPosition > 16) {
Start ();
} else if (roomList.Contains (roomPosition)) {
Start ();
} else {
roomList.Add (new MazeList (roomPosition));
Start ();
}
Any help would be greatly appreciated, thanks.
Answer by RobAnthem · Jan 02, 2017 at 11:07 PM
The list does not contain integers, it contains your room objects that contain integers. Lookup predicate searches, you can find objects based on properties in them from a list, it would be best just to check if the predicate is null or not. I am on my phone so I can't post examples till later.
what would i have to change to make it add the integer ins$$anonymous$$d to the list ins$$anonymous$$d of adding the room objects?
If there's never two rooms with the same int, you could use a Dictionary