Answer the question
In order to leave comments, you need to log in
Where is the error in the code (input in Unity)?
Hello!
There is a code (yes, clumsy, because I'm a beginner):
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class Chose : MonoBehaviour {
public int i=0;
public string [] m = new string[100];
public List <string> films = new List<string>(100);
public void Changename(string str)
{
films.Add(str);
i += 1;
Debug.Log("Имя" + i +", название фильма - " + str);
}
public void WriteAllOfThem()
{
foreach (string p in films)
{
Debug.Log (p);
}
}
}
class Film
{
public string Name { get; set; }
}
Answer the question
In order to leave comments, you need to log in
You may well have Changename without a parameter.
As you indicated on your screen with red arrows, this is not the ability to transfer text from the text field, but to the method to shove something from the Editor (in no way connected with the input),
you need to specify somewhere in the script or get a link to the
InputField
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Collections.Generic;
public class Chose : MonoBehaviour {
public InputField nameField;
public int i=0;
public string [] m = new string[100];
public List <string> films = new List<string>(100);
public void Changename()
{
string newName = nameField.text;
films.Add(newName );
i += 1;
Debug.Log("Имя" + i +", название фильма - " + newName );
}
public void WriteAllOfThem()
{
foreach (string p in films)
{
Debug.Log (p);
}
}
}
class Film
{
public string Name { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question