private void OnTriggerEnter(Collider col) { if (col.gameObject.name.StartsWith("Rock")) { DontDestroyOnLoad(txtScore2); LoadScene.EndGame(); } Vector3 newPos = new Vector3(); switch (col.gameObject.name) { case "Right_Border": this.gameObject.transform.DetachChildren(); newPos = GameObject.Find("Left_Border").transform.position; newPos.x += 1.5f; newPos.y = 0.5f; newPos.z = this.transform.position.z; transform.position = newPos; break; case "Left_Border": this.gameObject.transform.DetachChildren(); newPos = GameObject.Find("Right_Border").transform.position; newPos.x -= 1.5f; newPos.y = 0.5f; newPos.z = this.transform.position.z; transform.position = newPos; break; case "Top_Border": this.gameObject.transform.DetachChildren(); newPos = GameObject.Find("Bottom_Border").transform.position; newPos.z += 1.5f; newPos.y = 0.5f; newPos.x = this.transform.position.x; transform.position = newPos; break; case "Bottom_Border": this.gameObject.transform.DetachChildren(); newPos = GameObject.Find("Top_Border").transform.position; newPos.z -= 1.5f; newPos.y = 0.5f; newPos.x = this.transform.position.x; transform.position = newPos; break; case "Apple(Clone)": if (bodyCount == 0) { newBodyPos = this.transform.position - transform.forward; } else { newBodyPos = bodyPart[bodyCount - 1].position - bodyPart[bodyCount - 1].forward; } setPoint(1); bodyCount++; Destroy(col.gameObject); SpawnFood.ate = true; bodyPart.Add((Instantiate(cube, newBodyPos, this.transform.rotation) as GameObject).transform); count++; break; case "bigFood(Clone)": for (int i = 0; i < 2; i++) { if (bodyCount == 0) { newBodyPos = this.transform.position - transform.forward; } else { newBodyPos = bodyPart[bodyCount - 1].position - bodyPart[bodyCount - 1].forward; } bodyCount++; bodyPart.Add((Instantiate(cube, newBodyPos, this.transform.rotation) as GameObject).transform); } setPoint(5); Destroy(col.gameObject); SpawnFood.ate = true; count++; break; case "Body(Clone)": if (col.gameObject.transform != bodyPart[0] && col.gameObject.transform != bodyPart[1]) { LoadScene.EndGame(); } break; } }