FormatException: Die Eingabezeichenfolge hatte kein korrektes Format. System.Number.StringToNumber (System.String str, .C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 FormatException: Die Eingabezeichenfolge hatte kein korrektes Format. System.Number.StringToNumber (System.String str, .

Post by Anonymous »

Ich bin ein Anfänger in Unity und habe ein Problem in meinem Projekt, genauer gesagt, es gibt ein Problem im Checkpoint-Skript und dieses Ergebnis
Fehler:

Code: Select all

FormatException: Input string was not in a correct format.
System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at \:0)
System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at \:0)
System.Int32.Parse (System.String s) (at \:0)
Checkpoint.Start () (at Assets/Script/Checkpoint.cs:38)
Ich hoffe, ihr könnt mir helfen, dieses Problem zu lösen, und das ist mein Skript:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEngine.UI;

public class Checkpoint : MonoBehaviour
{
[HideInInspector]
public int lap = 0;
[HideInInspector]
public int checkPoint = -1;
int checkPointCount;
int nextCheckpoint = 0;
Dictionary visited = new Dictionary();
public Text lapText;
[HideInInspector]
public bool missed = false;
public GameObject PrevCheckpoint;

//Start is called before the first frame update
void Start()
{
GameObject[] checkpoints = GameObject.FindGameObjectsWithTag("Checkpoint");
checkPointCount = checkpoints.Length;

foreach (GameObject checpoint in checkpoints)
{
if (checpoint.name == "0")
{
PrevCheckpoint = checpoint;
break;
}
}

foreach (GameObject cp in checkpoints)
{
visited.Add(Int32.Parse(cp.name), false);
}
}

// Update is called once per frame (eror lap gak mau nambah)
void OnTriggerEnter(Collider col)
{
Debug.Log("colision");
if (col.gameObject.tag == "Checkpoint")
{
int checkpointCurrent = int.Parse(col.gameObject.name);

if (checkpointCurrent == nextCheckpoint)
{
PrevCheckpoint = col.gameObject;
visited[checkpointCurrent] = true;
checkPoint = checkpointCurrent;
if (checkPoint == 0 && gameObject.tag == "Player")
{
lap++;
lapText.text = "Lap: " + lap;
}

nextCheckpoint++;
if (nextCheckpoint >= checkPointCount)
{
var keys = new List(visited.Keys);
foreach (int key in keys)
{
visited[key] = false;
}
nextCheckpoint = 0;
}
}
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post