我在游戏中遇到问题;当玩家与障碍物碰撞时,将根据障碍物的标签检查玩家的网格,如果它们匹配,则更改玩家的网格。它可以在编辑器中工作,但在构建到APK后无法工作。顺便说一句,我可以缩写比较标记吗?
碰撞
public void OnTriggerEnter(Collider other)
{
if (Regex.IsMatch(other.gameObject.tag, "^(Cube|Sphere|Prism|[A-Z]) Instance$") == (other.CompareTag(playerMesh.mesh.name))) //If player collides with an obstacle
{
//If the collided gameObject has the same mesh as the player
for (int i = 0; i < meshes.Length; i++)
{
if (meshes[i].name == other.transform.tag[0].ToString())
{
Camera.main.GetComponent<Animation>().Play();
other.GetComponent<AudioSource>().Play();
StartCoroutine(Hit());
playerMesh.mesh = meshes[i + 1]; //Changes the player's mesh
indtX++;
Alphabetconfig();
}
}
print("sarua");
GameObject tempCollisionParticle = Instantiate(collisionParticle, transform.position, Quaternion.identity); //Instantiates a collisionParticle to the player's position
tempCollisionParticle.GetComponent<Renderer>().material.color = playerRen.material.color; //Sets its color identical to the player's color
Destroy(tempCollisionParticle, 1.2f); //Destroys it after x seconds
}
else if (other.CompareTag("Token"))
{
gameIsOver = false;
FindObjectOfType<ScoreManager>().IncrementToken();
//token sound
Destroy(Instantiate(tokenParticle, transform.position, Quaternion.identity), 1.2f);
Destroy(other.gameObject);
}
else if (other.CompareTag("Health"))
{
gameIsOver = false;
//healthsound
stats.playerCurrenthealth++;
if (stats.playerCurrenthealth > stats.playerMaxhealth)
{
stats.playerCurrenthealth = stats.playerMaxhealth;
}
Destroy(other.gameObject);
}
else if (other.CompareTag("Book"))
{
gameIsOver = false;
//healthsound
StartCoroutine(ImmuneTime());
Destroy(other.gameObject);
}
else if (other.CompareTag("Wrench"))
{
gameIsOver = false;
//HealthSound
stats.playerCurrenthealth++;
if (stats.playerCurrenthealth > stats.playerMaxhealth)
{
stats.playerCurrenthealth = stats.playerMaxhealth;
}
Destroy(other.gameObject);
}
else if (other.CompareTag("Pen"))
{
gameIsOver = false;
//healthsound
StartCoroutine(FlyTime());
Destroy(other.gameObject);
}
else //If the tags are different
{
stats.Immune = false;
gameIsOver = false;
stats.Damage(1);
if (stats.playerCurrenthealth < 0)
{
gameIsOver = true; //Game is over
//Plays 'deathSound'
trailRen.enabled = playerRen.enabled = false;
GetComponent<Collider>().enabled = false;
FindObjectOfType<GameManager>().EndPanelActivation();
}
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
//FindObjectOfType<ScoreManager>().IncrementScore(); //Increments score
//Plays Colides
}
}
我知道问题所在,但我不知道如何解决,就像我在android上构建脚本反向功能时一样,if
变成else
,而else
变成`if 。我不知道会发生什么,这是来自编辑器还是脚本?