Translate from Visual Scripting to C#

Hi, a few months ago, I tried to switch from c# script to visual script but now I changed my mind to use c# anyway. Can anyone help me translate this visual script to c# script because I am still confused with the dictionary related stuff, thanks.

1 Like

What are the types of the variable, i need this to make it.

I dont know how the variable answers gets assigned in your script so read the comments.

This is what i made:

using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using System;
using TMPro;

public class YourClass : MonoBehaviour
{
    // you need to assign this in the inspector
    public int amountOfAnswer;

    // you need to assign these in the inspector
    public TMP_InputField[] pointInputFields;
    public TMP_InputField[] answerInputFields;

    // i dont know where you get this from but it doesnt show in the inspector because its a dictionary
    // it will also give errors because the variable is not set
    public Dictionary<string, int> answers;

    void Start()
    {
        answers.Clear();

        int i = 0;
        foreach (TMP_InputField pointInputField in pointInputFields)
        {
            string answerFieldText = answerInputFields[i].text.ToUpper().Trim();

            if (!answers.ContainsKey(answerFieldText))
            {
                if (amountOfAnswer == i)
                {
                    break;
                }
                else
                {
                    int pointFieldText = Int32.Parse(pointInputField.text);

                    answers.Add(answerFieldText, pointFieldText);

                    return;
                }
            }

            i++;
        }
    }
} 

Hope that helps

Why? :grinning:

I’m just collecting opinions.

1 Like

i dont know what his reason is,
but mine is that it is slow in both dev time and run time

2 Likes

thanks for helping, I’ll try it to see the result

1 Like

It’s the same reason for me

2 Likes