Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do i create list?

Discussion in 'Editor & General Support' started by ShokTheIV, Dec 2, 2020.

  1. ShokTheIV

    ShokTheIV

    Joined:
    Nov 19, 2020
    Posts:
    17
    Hello guys im not new to unity but i havent coded in a while and before to create a list all i had to do was
    Code (CSharp):
    1. public List<Gun> gun;
    2.  
    Now there an error saying "it cant find the namespace" even tho i included
    Code (CSharp):
    1.  using System;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
     
  2. Lionious

    Lionious

    Joined:
    Apr 19, 2013
    Posts:
    48
    do you have scriptableobject script or something called Gun? if not then u try to import something not exist in that list. maybe you meant List<GameObject> guns;

    there alot of stuff can be imported inside < > like Transform , int , float and much other, whatever ur need case is.
     
  3. ShokTheIV

    ShokTheIV

    Joined:
    Nov 19, 2020
    Posts:
    17
    Oh , i made a class called "Gun" to store different types of guns, and now i need to access them thru a list due to some restrictions i have
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    You probably want
    using System.Collections.Generic
    .

    At least in C# this has always been the namespace used for generic lists in the .NET framework.
     
    Last edited: Dec 2, 2020
    Joe-Censored likes this.
  5. ShokTheIV

    ShokTheIV

    Joined:
    Nov 19, 2020
    Posts:
    17
    OMG im such an idiot, thank you so much.
     
  6. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,184
    Maybe all developers are, but many are street-smart and use an IDE, that automatically imports namespaces. At least Rider and Visual Studio do and it helps with situations like trying to implement a Coroutine. In this case, although Unity's trickster implementation doesn't have to do much with collections, you still need
    System.Collections
    imported, so you can use IEnumerator as the return type of Coroutines.

    I also think it wouldn't be too far stretched an assumption that
    System.Collections
    also imports everything nested within it, but well it doesn't.