так что это буквально ошибка в моей игре, когда игрок сталкивается с объектом, там будет меняться сетка с индексом на нем, всякий раз, когда он сталкивается с тегом 10 на нем, следующий равен 2, это должно быть 11 и т. Д. .
посмотрите на мой сценарий:
public void OnTriggerEnter(Collider other)
{
if (Regex.IsMatch(other.gameObject.tag, "^(Cube|Sphere|Prism|[A-Z]|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30) ")) //If player collides with an obstacle
{
string indicatorCompareTag = "w";
if (Application.platform == RuntimePlatform.WindowsEditor)
{
indicatorCompareTag = playerMesh.mesh.name;
}
else if (Application.platform == RuntimePlatform.Android)
{
indicatorCompareTag = gameObject.name + " Instance";
}
print("Player Mesh name : " + indicatorCompareTag);
print("Collide tag name : " + other.transform.tag);
print(playerMesh.mesh.name + " compare tag with " + other.transform.tag + " ? " + other.CompareTag(playerMesh.mesh.name));
if (other.CompareTag(indicatorCompareTag)) //If the collided gameObject has the same mesh as the player
{
Camera.main.GetComponent<Animation>().Play();
for (int i = 0; i < meshes.Length; i++)
{
print("Ganti");
if (meshes[i].name == other.transform.tag[0].ToString() || meshes[i].name== other.transform.tag.Substring(0).ToString())
{
score.isRighPath = true;
other.GetComponent<AudioSource>().Play();
audio.play("SwithcedShape");
score.IncrementScore();
StartCoroutine(Hit());
playerMesh.mesh = meshes[i + 1]; //Changes the player's mesh
gameObject.name = meshes[i + 1].name;
if (indtX >= allAlphabets.Count)
indtX = 0;
else
indtX++;
Alphabetconfig();
}
}
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
//FindObjectOfType<ScoreManager>().IncrementScore(); //Increments score
//Plays Colides
}
проблема, которую я думаю в этой функции, я пробовал с подстрокой, но ничего не изменилось
if (meshes[i].name == other.transform.tag[0].ToString() || meshes[i].name== other.transform.tag.Substring(0).ToString())
дляизмените сетку с индексом, там будет изменен фильтр сетки, когда имя сетки совпадает с тегом.
if (other.CompareTag(indicatorCompareTag)) //If the collided gameObject has the same mesh as the player
{
Camera.main.GetComponent<Animation>().Play();
for (int i = 0; i < meshes.Length; i++)
{
print("Ganti");
if (meshes[i].name == other.transform.tag[0].ToString())
{
score.isRighPath = true;
other.GetComponent<AudioSource>().Play();
audio.play("SwithcedShape");
score.IncrementScore();
StartCoroutine(Hit());
playerMesh.mesh = meshes[i + 1]; //Changes the player's mesh
gameObject.name = meshes[i + 1].name;
if (indtX >= allAlphabets.Count)
indtX = 0;
else
indtX++;
Alphabetconfig();
}
public void Alphabetconfig()
{
activeAlphabets.Clear();
for (int i = indtX; i <= indtX + 4; i++)
{
activeAlphabets.Add(allAlphabets[i]);
}
}
введите описание ссылки здесь