- Home /
Question by
syarifabdr22 · Oct 19, 2019 at 11:59 AM ·
scripting problembuildingerror build
Can't well compiled the script when build to android unity
I have the problem in my game when the player collides with an obstacle the mesh of player changed with the same name mesh with tag, it's work in the editor but not work after building to the apk, am I wrong with the script? and also can I abbreviate the compare tag?
collision.cs
public GameObject collisionParticle, tokenParticle;
//public ObstacleManager obsManager;
public List<GameObject> allAlphabets = new List<GameObject>();
public List<GameObject> activeAlphabets = new List<GameObject>();
private Color[] colors = new Color[3] { Color.red, Color.blue, Color.green };
private TrailRenderer trailRen;
private Renderer playerRen;
private MeshFilter playerMesh;
Stats stats;
G_P_Movement movement;
Animator anim;
[HideInInspector]
public bool gameIsOver = false;
public int indtX;
// Use this for initialization
void Start()
{
stats = FindObjectOfType<Stats>();
print(GetComponent<MeshFilter>().mesh.name);
trailRen = GetComponent<TrailRenderer>();
playerRen = GetComponent<Renderer>();
playerMesh = GetComponent<MeshFilter>();
movement = FindObjectOfType<G_P_Movement>();
gameIsOver = false;
indtX = 0;
Alphabetconfig();
}
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Cube Instance") || other.CompareTag("Sphere Instance") || other.CompareTag("Prism Instance") || other.CompareTag("A Instance")
|| other.CompareTag("B Instance") || other.CompareTag("C Instance") || other.CompareTag("D Instance") || other.CompareTag("E Instance") || other.CompareTag("F Instance")
|| other.CompareTag("G Instance") || other.CompareTag("H Instance") || other.CompareTag("I Instance") || other.CompareTag("J Instance")
|| other.CompareTag("K Instance") || other.CompareTag("L Instance") || other.CompareTag("M Instance") || other.CompareTag("N Instance") || other.CompareTag("O Instance")
|| other.CompareTag("P Instance") || other.CompareTag("Q Instance") || other.CompareTag("R Instance") || other.CompareTag("S Instance") || other.CompareTag("T Instance")
|| other.CompareTag("U Instance") || other.CompareTag("V Instance") || other.CompareTag("W Instance") || other.CompareTag("X Instance") || other.CompareTag("Y Instance")
|| other.CompareTag("Z Instance")) //If player collides with an obstacle
{
if (other.CompareTag(GetComponent<MeshFilter>().mesh.name)) //If the collided gameObject has the same mesh as the player
{
FindObjectOfType<Camera>().GetComponent<Animation>().Play();
print("sarua");
for (int i = 0; i < meshes.Length ; i++)
{
if (meshes[i].name == other.transform.tag[i].ToString())
{
other.GetComponent<AudioSource>().Play();
StartCoroutine(Hit());
playerMesh.mesh = meshes[i + 1]; //Changes the player's mesh
indtX++;
Alphabetconfig();
if (indtX > allAlphabets.Count)
{
indtX = 0;
}
}
}
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
//FindObjectOfType<ScoreManager>().IncrementScore(); //Increments score
//Plays Colides
}
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 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
}
Comment
I can't help you on your problem unless you describe it more, but yes, that entire compare block can be removed simply by using physics layers.
Your answer
Follow this Question
Related Questions
How do you destroy a GameObject during the build process? 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Graphic Rebuild Loop Error 2 Answers
building error in my video project apk 0 Answers
MacOS Sierra Can't Use pdb2mdb.exe? 0 Answers