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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

help with select system with a list [Solved]

Discussion in 'Scripting' started by welpie21, Mar 9, 2017.

  1. welpie21

    welpie21

    Joined:
    Dec 23, 2014
    Posts:
    49
    hello good afternoon for the people who life near to my time zone.

    i have a question. im making a taskcontroller but there is one problem.

    i have a list and is assigned to an class that contains the following variables :
    Code (CSharp):
    1. public bool Finished { get; set; }
    2. public bool IsSelected;
    3. public int Amount { get; set; }
    4. public int Priority { get; set; }
    5. public string GivenTask { get; set; }
    6. public string TaskDescription { get; set; }
    everything is working, but i dont know how to make a *Select System*, but i tried the following code :
    Code (CSharp):
    1. public void AssignTask(int index)
    2.     {
    3.         for (int i = 0; i < TaskList.Count; i++)
    4.         {
    5.             if (TaskList [i].Selected)
    6.             {
    7.                 break;
    8.             }
    9.  
    10.             if (!TaskList [i].Selected)
    11.             {
    12.                 TaskList [index].Selected = true;
    13.             }
    14.         }
    15.     }
    Code (CSharp):
    1. if (Input.GetKeyDown (KeyCode.Space))
    2.         {
    3.             AddTask ();
    4.             TaskList = TaskList.OrderBy (x => x.Priority).ThenBy (x => x.Amount).Reverse ().ToList ();
    5.             AssignTask (index);
    6.         }
    its not done yet, i want that the select system is getting to work.

    but in the update function i call the "AssigningTask" when a button is pressed, for me its space.

    so everytime when i hit space, i see sometimes that multiple tasks are selected, i want only to have 1 task selected but you can't select others anymore.

    i hope im clear enough about my issue, and have a nice day.
     
  2. welpie21

    welpie21

    Joined:
    Dec 23, 2014
    Posts:
    49
    never mind, i fixed my own issue.