Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by SteamPunkDevil_ · Apr 19, 2016 at 08:22 PM · c#gameobjectlist

Error With Blocks = Block1.Intersect(Block2); error CS0266:

On line 109 I get an error saying :

Assets/Code/GenGround.cs(109,34): error CS0266: Cannot implicitly convert type \`System.Collections.Generic.IEnumerable' to \`System.Collections.Generic.List<UnityEngine.GameObject>'. An explicit conversion exists (are you missing a cast?

But I am confused as they are the same type. How do I fix this? Thanks

 using UnityEngine;
 using System.Collections;
 using System.Linq;
 //using System;
 using System.Collections.Generic;
 
 public class GenGround : MonoBehaviour {
 // Use this for initialization
 public GameObject[] terrainTypes;
 void Start () {
                                 int x = 0;
                                 int y = 0;
                                 int i = 0;
                                 GameObject[] itemList = new GameObject[10000];
                                 terrainTypes = GameObject.FindGameObjectsWithTag ("Terrain").OrderBy( go => go.name).ToArray();
                         List<GameObject> WaterDeepOpts = new List<GameObject>();
                                 WaterDeepOpts.Add(terrainTypes[3]);
                         WaterDeepOpts.Add(terrainTypes[4]);
                         List<GameObject> WaterShallowOpts = new List<GameObject>();
                                 WaterShallowOpts.Add(terrainTypes[3]);
                                 WaterShallowOpts.Add(terrainTypes[4]);
                         WaterShallowOpts.Add(terrainTypes[1]);
                         List<GameObject> SandOpts = new List<GameObject>();
                                 SandOpts.Add(terrainTypes[0]);
                                 SandOpts.Add(terrainTypes[1]);
                         SandOpts.Add(terrainTypes[4]);
                         List<GameObject> GrassOpts = new List<GameObject>();
                                 GrassOpts.Add(terrainTypes[0]);
                                 GrassOpts.Add(terrainTypes[1]);
                         GrassOpts.Add(terrainTypes[2]);
                         List<GameObject> StoneOpts = new List<GameObject>();
                                 StoneOpts.Add(terrainTypes[0]);
                         StoneOpts.Add(terrainTypes[2]);
                                 List<GameObject> Block1 = new List<GameObject>();
                         List<GameObject> Block2 = new List<GameObject>();
                         foreach(GameObject g in terrainTypes) {
                                                                 Debug.Log (g);
                                 };
                                 itemList[i] = Instantiate (terrainTypes[Random.Range(0,terrainTypes.Length)], new Vector3(0,0,0),Quaternion.identity) as GameObject;
                                 x = x + 10;
                                 i = i + 1;
                                 while (y < 1000) {
             if (i > 0 && i < 100)
             {
                 //Debug.Log (i);
                 if (itemList[i - 1].name == "WaterDeep(Clone)")
                 {
                                     itemList[i] = Instantiate(WaterDeepOpts[Random.Range(0, WaterDeepOpts.Count())], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                 }
                 else if (itemList[i - 1].name == "WaterShallow(Clone)")
                 {
                     itemList[i] = Instantiate(WaterShallowOpts[Random.Range(0, WaterShallowOpts.Count())], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                     //Debug.Log (itemList [i]);
                 }
                 else if (itemList[i - 1].name == "Sand(Clone)")
                 {
 
                                         itemList[i] = Instantiate(SandOpts[Random.Range(0, SandOpts.Count())], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                 }
                 else if (itemList[i - 1].name == "Grass(Clone)")
                 {
                                     itemList[i] = Instantiate(GrassOpts[Random.Range(0, GrassOpts.Count())], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                 }
                 else if (itemList[i - 1].name == "Stone(Clone)"){
                                 itemList[i] = Instantiate(StoneOpts[Random.Range(0, StoneOpts.Count())], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                 }
                 else {
                     itemList[i] = Instantiate(terrainTypes[Random.Range(0, terrainTypes.Length)], new Vector3(x, 0, y), Quaternion.identity) as GameObject;
                 }
                } else if (i > 100){
                             if (itemList[i - 1].name == "WaterDeep(Clone)")
                             {
                             Block1 = WaterDeepOpts;
                             }
                             else if (itemList[i - 1].name == "WaterShallow(Clone)")
                             {
                             Block1 = WaterShallowOpts;
                             }
                             else if (itemList[i - 1].name == "Sand(Clone)")
                             {
                                     Block1 = SandOpts;
                             }
                             else if (itemList[i - 1].name == "Grass(Clone)")
                             {
                                 Block1 = GrassOpts;
                             }
                             else{
                             Block1 = StoneOpts;
               }
                             if (itemList[i - 100].name == "WaterDeep(Clone)")
                             {
                             Block2 = WaterDeepOpts;
                             }
                             else if (itemList[i - 100].name == "WaterShallow(Clone)")
                             {
                             Block2 = WaterShallowOpts;
                             }
                             else if (itemList[i - 100].name == "Sand(Clone)")
                             {
                                     Block2 = SandOpts;
                             }
                             else if (itemList[i - 100].name == "Grass(Clone)")
                             {
                                 Block2 = GrassOpts;
                             }
                             else{
                              Block2 = StoneOpts;
                             }
                 List<GameObject> Blocks = new List<GameObject>();
                                 Blocks = Block1.Intersect(Block2);
             } else {
                             itemList[i] = Instantiate (terrainTypes[Random.Range(0,terrainTypes.Length)], new Vector3(x,0,y),Quaternion.identity) as GameObject;
                                                                 }
                                                                 x = x + 10;
                                                                 i = i + 1;
                                                                 //Debug.Log(itemList[i]);
                                                                 if (x == 1000) {
                                                                                                 y = y + 10;
                                                                                                 x = 0;
 
                                                                 };
 
                                 };
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }
 }
 /*
    WaterDeep {
    WaterShallow
    }
    WaterShallow{
    WaterDeep
    Sand
    }
  */
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by jgodfrey · Apr 19, 2016 at 10:17 PM

I think you need to convert the result back to a list. Specifically:

 Blocks = Block1.Intersect(Block2).ToList();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SteamPunkDevil_ · Apr 19, 2016 at 10:39 PM 0
Share

Thanks I would have never have thought of that but it makes sense, I guess .Intersect makes an array.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What range of values need to be inserted if we need to pull a random item from the list? 0 Answers

Edit properties of certain list items,Changing properties of objects in a list (c#) 1 Answer

Using a specific function from a generic object. 0 Answers

How to delete an object if there is another object of the same type at that position ? 1 Answer

Getting objects out of a list and then comparing them 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges