Search Unity

help translating pseudocode into C#

Discussion in 'Scripting' started by Dobe, Dec 4, 2012.

  1. Dobe

    Dobe

    Joined:
    Nov 13, 2012
    Posts:
    11
    I've recently begun working with unity C# and I've been having a lot of trouble overcoming a seemingly simple task. I am basically writing a simple script that asks a parent for a list of it's children, and then loops through the children comparing their names to a master list that I have created.

    I'm struggling with getting this to function and the only thing I can think to do is to give you guys some psuedo code and see if anyone can help me create a functioning script.



     
  2. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    If simple things like loop constructs and arrays/lists are stumping you I'd suggest you invest in a C# book or find some a good online course or set of tutorials that teaches from basic command structures and primitive types though to collections. It'll save you a lot of time in the long run.
     
    Last edited: Dec 4, 2012
  3. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    a bunch of parentheses could be removed, but for completeness i kept them all.

    Code (csharp):
    1.  
    2. int count = 0;
    3. List<Transform> failedObj = new List<Transform>();
    4.  
    5. foreach(Transform childTransform in transform)
    6. {
    7.   bool hasMatched = false;
    8.  
    9.   foreach(Transform obj in MasterList)
    10.   {
    11.     if (childTransform == obj)
    12.     {
    13.       hasMatch = true;
    14.       break;
    15.     }
    16.   }
    17.  
    18.   if(hasMatch)
    19.   {
    20.     failedObj.Add(childTransform);
    21.   }
    22.  
    23.   count++;
    24. }
    25.  
     
  4. Dobe

    Dobe

    Joined:
    Nov 13, 2012
    Posts:
    11
    I agree entirely with what you're suggesting. That is what I am doing and plan on continuing to do, however my current project is time sensitive and i'm having to work in an area I am not comfortable with yet.
     
  5. Dobe

    Dobe

    Joined:
    Nov 13, 2012
    Posts:
    11
    thank you Landern, this gives me a great place to start. I appreciate your time.