Beispiel #1
0
    public void ChangeTargetColor(string targetName, string colorName)
    {
        if (currentAnswerIndex < 0)
        {
            return;
        }

        Debug.Log(string.Format("GameManager.ChangeTargetColor2 target: {0}, color: {1}", targetName, colorName));

        // Get current prefab gameobject
        GameObject answerRowPrefab = answers[currentAnswerIndex];

        // Get prefab script (reference to renderer and material
        AnswerRow answerRow = answerRowPrefab.GetComponent <AnswerRow>();

        // Get targetColor enum
        GameColor targetColor = GetGameColorForString(colorName);

        // Get index for target
        int index = GetIndexForTargetName(targetName);

        // Set answer row color
        answerRow.SetByPosition(index, targetColor);

        // Get target material
        var targetMaterial = FindTarget(targetName);

        if (targetMaterial == null)
        {
            Debug.Log("GameManager.ChangeTargetColor2 target is null");
        }
        else
        {
            switch (colorName)
            {
            case "red":
            {
                targetMaterial.color = Color.red;
                break;
            }

            case "blue":
            {
                targetMaterial.color = Color.blue;
                break;
            }

            case "green":
            {
                targetMaterial.color = Color.green;
                break;
            }

            case "yellow":
            {
                targetMaterial.color = Color.yellow;
                break;
            }

            default:
            {
                break;
            }
            }
        }
    }