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 to program choosing a max of objects in C#

Discussion in 'Scripting' started by jo6x, May 4, 2016.

  1. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    I've got 10 objects and I only just may choose 5, so I need to wright a code but the way I know how to do it seams endless.
    The code I know how to use:
    Code (CSharp):
    1. if (A && B && C && D || A && B && C && E || A && B && C && F
    2. || A && B && C && G || A && B && C && H || A && B && C && I || A && B && D && I
    3. || and more, and more, and more ................................................................)
    4.         {
    5.             blockChoiceMaterial = true;
    6.             Debug.Log ("blocking");
    7.         }
    Now I can make it work by writing all of the combinations but this is becoming a very large script.
    does someone know how to do it in a shorter way.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,376
    Does this have anything to do with yesterdays post?
    http://forum.unity3d.com/threads/ho...a-lot-of-objects-to-choose-with-a-max.402000/

    You've now shared 3 different example code, and not one of them seem related to one another in any cohesive manner.

    Example... this one you ask to choose 5 of 10... I don't see 10 things there, nor are your comparisons in segments of 5 (they're 4).


    What are you even attempting to do? Can you explain the ACTUAL thing you're attempting. Like what are these 10 things, why do you need to choose 5 of them, under what criteria do you have to choose those 5 things, what are you then going to do with those 5 things?

    Give me a frame of reference... I have no idea what you're even attempting here, and your example code is cryptic at best.
     
    Last edited: May 4, 2016
    Ryiah likes this.
  3. Duri

    Duri

    Joined:
    Dec 5, 2014
    Posts:
    29
    1. Create a List<T>, been T something like string.
    2. Create a loop that will execute until that list's size is 5.
    3. Every time you select an object, delete it from the selection menu (so you don't have repeated selections in your list) and add it to the list. By "deleting" I mean not showing then in the selection menu (either you delete it or not show it).
     
  4. Duri

    Duri

    Joined:
    Dec 5, 2014
    Posts:
    29
    And yeah, lordofduct is right, be more "open" when you ask for something. What I wrotte was what I think is your idea.
     
  5. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    Oke, I've got a game where I need to choose a max of 4 objects out of 10. When I made that choice of 4 objects the game will make it clear that I choose the wright 4 objects, otherwise I need to go back and change it.
    The objects I choose are going to be visible in the canvas witch I carry with me along the game.
    Those 4 objects I take with me will keep me save and alive, so it's like I only may choose 4 cards out of 10


    That's correct.

    That's wright, this has to be 4 objects out of 10 (my first thought was 5 but I made it 4).

    My English is poor, I've got to do it with some basics, so it's a bit difficult for me, sorry for that.
    What Duri just explained is what I'm looking for, its the list I needed what I couldn't recall.

    Anyway, thanks for your reply, I'll hope to be more clear next time.
     
  6. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    Hi Duri,
    That was the one I couldn't recall, maybe of my age. :)

    Thanks for reminding me.