Hello, I have this script:
using UnityEngine;
using System.Collections;
public class StringSplit : MonoBehaviour {
public int test = 1234;
public string abc;
public string ausgabe;
public string asdf;
public int i = 1;
public int zahl1;
public int zahl2;
public int zahl3;
public int zahl4;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
abc = test.ToString();
foreach (char c in abc)
{
if (test < 10)
{
zahl1 = c;
i = 0;
}
if (test < 100 && test > 9)
{
if (i == 1)
{
zahl1 = c;
}
if (i == 2)
{
zahl2 = c;
i = 0;
}
}
if (test < 1000 && test > 99)
{
if (i == 1)
{
zahl1 = c;
}
if (i == 2)
{
zahl2 = c;
}
if (i == 3)
{
zahl3 = c;
i = 0;
}
}
if (test < 10000 && test > 999)
{
if (i == 1)
{
zahl1 = c;
}
if (i == 2)
{
zahl2 = c;
}
if (i == 3)
{
zahl3 = c;
}
if (i == 4)
{
zahl4 = c;
i = 0;
}
}
i++;
}
}
}
But when I wanna split “1234” I get:
zahl1 = 50, zahl2 = 51, zahl3 = 52 and zahl4 = 49, but I want zahl1 = 1, zahl2 = 2, zahl3 = 3 and zahl4 = 4. Where is my error?