Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

How do I search a list for a Vector3?

$
0
0
I have a list that holds a number of Vector3s, and before I add another Vector3 to the list, I want to check to make sure the list doesn't already contain that value. When I use list.Exists(), it gives me an error: "The best overloaded method match for `System.Collections.Generic.List.Exists(System.Predicate)' has some invalid arguments" I've tried inputting the value I need to search for in different ways, but I always get this error. Does anyone know what I'm doing wrong? The error occurs at line 88 in the CheckForValidSpots function. Any advice would be super helpful! using UnityEngine; using System.Collections; using System.Collections.Generic; public class LevelCreatorScript : MonoBehaviour { public GameObject roomPrefab; public int roomCount = 5; int doorCount = 0; public float roomHeight = 15.0f; public float roomWidth = 24.0f; List pastRooms = new List(); Vector3 currentRoom; List futureRooms = new List(); List validSpots = new List(); List doorDirections = new List(); void Start () { futureRooms.Add(new Vector3(0, 0, 0)); CreateLevel(); } void CreateLevel() { while ( (futureRooms.Count + pastRooms.Count + 1) < roomCount ) { if (doorCount == 0) { validSpots.Clear(); if (true) { pastRooms.Add(currentRoom); Debug.Log( "Adding current room: " + currentRoom + "to pastRooms at Index[" + (pastRooms.Count - 1) + "]."); }if (futureRooms.Count > 0) { currentRoom = futureRooms[0]; futureRooms.RemoveAt (0); if(pastRooms.Count == 0) { doorCount = Random.Range(2,5); }else { doorCount = Random.Range(1,5); } } }else { //tries to make a new room //determine valid placement spots for new rooms //puts all valid placement spots in a new list: validSpots //if validSpots.count < doorCount, DoorCount = validSpots.Count //randomly chooses between one of the rooms to make a new room } } } void AddDirections(List directions) { directions.Add(new Vector3(0, 0, roomHeight)); directions.Add(new Vector3(roomWidth, 0, 0)); directions.Add(new Vector3(0, 0, -roomHeight)); directions.Add(new Vector3(-roomWidth, 0, 0)); } void CheckForValidSpots(Vector3 roomLocation) { for (int n = 0; n < 4; n++) { Vector3 locationToCheck = new Vector3( roomLocation.x + doorDirections[n].x, 0, roomLocation.z + doorDirections[n].z); //HERE IS WHERE I GET THE ERROR if( !pastRooms.Exists(locationToCheck) && !futureRooms.Exists(locationToCheck) ) { validSpots.Add(locationToCheck); } } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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