Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by koko.digital · Nov 22, 2012 at 09:53 AM · c#coroutineyeild

c# using Lists and IEnumerator's in the same class?

I'm an AS3 programmer and im just getting into Unity so i'm sorry if this is a stupid mistake on my part :p

At the top of the standard c# class that extends MonoBehavior we have the following

 using UnityEngine;
 using System.Collections;
 
 public class ClassName : MonoBehaviour {

When i tried to use a list like so

 private List<string> animationNames;

I got an error saying that the type or namespace 'List' could not be found! After a bit of googling i came across an article that explained I needed to change the top to the following

 //using System.Collections;
 using System.Collections.Generic;

This worked great, I'm a little confused as to why that fixes it as in actionscript if you import a level up it imports all classes in folders?

Anyway, this worked ok for a while, then i got onto Courtine and Yeilds, which return IEnumerator, which now doesnt work because of the 'using' change. and if i change it back List's break. im sure that this is just a schoolboy error on my part...

Any help would be greatly appreciated and thanks in advance!

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 dukearena · Nov 22, 2012 at 10:07 AM

IEnumerators need System.Collections, List needs System.Collections.Generics.. This is not for Unity but it is a C# rule, you must choose what library are necessary for your script..

You can add infinite number of imports statemets like:

     using UnityEngine;
     using System.Collections;
     using System.Collections.Generics;
     using System;
     using System.Text;
     .. and others..

If you have some problem with a class (like List) you can find a good documentation (and what import needs) in MSDN online ( http://msdn.microsoft.com/it-it/library/6sh2ey19.aspx )

I hope your question is satisfied :D

Ps. this is the basic of C#, I recommend you to take some c# tutorial

Comment
Add comment · Show 2 · 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 koko.digital · Nov 22, 2012 at 10:23 AM 0
Share

Thanks dukearena, I honestly dont know why I didn't try this. I understand you can import multiple things. It was my understanding (from AS3) that using System.Collections would import everything within there including System.Collections.Generic. I am looking into getting some books on c# and unity, but all the unity books are about 3.5 as 4 is a newish release, so i think im going wait a bit!

avatar image dukearena · Nov 22, 2012 at 10:29 AM 0
Share

No problems, this mistakes happens a lot of times for me :D You only need some experience

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

10 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Why is my Mathf.Movetowards Coroutine executing instantly? 2 Answers

Coroutine gets stuck randomly? 1 Answer

Yield not working properly 1 Answer


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