Два типа движения в единственной функции обновления

Я создал метод для получения уникальной комбинации всех целых элементов в массиве, как показано ниже. Я использовал Tuple для представления пары или комбинации чисел:

private static void CombinationsOfItemsInAnArray()    
{
        int[] arr = { 10, 50, 3, 1, 2 }; //unique elements

        var numberSet = new HashSet<int>();
        var combinationList = new List<Tuple<int, int>>();
        foreach (var number in arr)
        {
            if (!numberSet.Contains(number))
            {
                //create all tuple combinations for the current number against all the existing number in the number set
                foreach (var item in numberSet)
                    combinationList.Add(new Tuple<int, int>(number, item));

                numberSet.Add(number);
            }
        }

        foreach (var item in combinationList)
        {
            Console.WriteLine("{{{0}}} - {{{1}}}",item.Item1,item.Item2);
        }
    }

Когда я вызываю этот метод в консольном приложении, я становлюсь ниже вывода:

{50} - {10}
{3} - {10}
{3} - {50}
{1} - {10}
{1} - {50}
{1} - {3}
{2} - {10}
{2} - {50}
{2} - {3}
{2} - {1}
0
задан Drudie 17 January 2019 в 07:39
поделиться

1 ответ

Я бы предложил просто обернуть блоки в Input.GetKey(KeyCode.LefyShift)

if(!Input.GetKey(KeyCode.LeftShift)
{
    if (Input.GetKey(KeyCode.W))
    {
         tf.position += (Vector3.up * speed);
    }
    else if (Input.GetKey(KeyCode.A))
    {
         tf.position += (Vector3.left * speed);
    }
    else if(Input.GetKey(KeyCode.S))
    {
         tf.position += (Vector3.down * speed);
    }
    else if(Input.GetKey(KeyCode.D))
    {
         tf.position += (Vector3.right * speed);
    }
}
else
{
    if (Input.GetKeyDown(KeyCode.W))
    {
         tf.position += Vector3.up;
    }
    else if (Input.GetKeyDown(KeyCode.A))
    {
         tf.position += Vector3.left;
    }
    else if (Input.GetKeyDown(KeyCode.S))
    {
         tf.position += Vector3.down;
    }
    else if (Input.GetKeyDown(KeyCode.D))
    {
         tf.position += Vector3.right;
    }
}
0
ответ дан derHugo 17 January 2019 в 07:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: