void OnTriggerEnter2D(Collider2D coll) { List <AddPortal.Tuple> portals = AddPortalScript.portals; //Debug.Log("collision with: " + coll.name); if ((coll.name.StartsWith(outputPortal.name))) { PortalId something = coll.gameObject.GetComponent <PortalId>(); int id = something.id; // Debug.Log("Collision portal id: " + id); AddPortal.Tuple onIndex = null; foreach (AddPortal.Tuple tup in portals) { if (tup.outputPortal.getId() == id) { onIndex = tup; break; } } Destroy(coll.gameObject); Destroy(onIndex.inputPortal.InputPortalGO); } if (coll.name.StartsWith(portalPart.name)) { Destroy(coll.gameObject, SnakeScript.moveTime); } }
void OnTriggerEnter2D(Collider2D coll) { if (portal) { return; } if (coll.name.StartsWith(foodPrefab.name)) { // Get longer in next Move call ate = true; // Remove the Food Destroy(coll.gameObject); score += foodScoreNormal; Loading.setScore(Loading.getLastLevelId(), score); scoreText.text = score.ToString(); eatSound.Play(); } else if (coll.name.StartsWith(decreaseSnakeLengthFoodPrefab.name)) { // Get shorter in next Move call shrink = true; desiredLengthOfSnake--; // Remove the Food Destroy(coll.gameObject); score += foodScoreDecrease; Loading.setScore(Loading.getLastLevelId(), score); scoreText.text = score.ToString(); eatSound.Play(); } else if (coll.name.StartsWith(incraseSnakeSpeedFoodPrefab.name)) { //increase speed of snake ??do we increase the lenght of snake as well?? UpdateSpeed(true); removeSpecialFood(); //score updated in UpdateSpeed(); } else if (coll.name.StartsWith(decreaseSnakeSpeedPrefab.name)) { //decrease speed UpdateSpeed(false); removeSpecialFood(); //score updated in UpdateSpeed(); } else if (coll.name.StartsWith(AddPortalSript.backgroundIn.name)) { portal = true; //Debug.Log("hura portal!"); List <AddPortal.Tuple> portals = AddPortalSript.portals; PortalId something = coll.gameObject.GetComponent <PortalId>(); int id = something.id; //Debug.Log("Collision portal id: " + id); AddPortal.Tuple onIndex = null; Instantiate(toPortalBobyPieceGO, coll.gameObject.transform.position, transform.rotation); foreach (AddPortal.Tuple tup in portals) { if (tup.outputPortal.getId() == id) { onIndex = tup; break; } } if (onIndex != null) { Vector3 head = new Vector3(dir.x, dir.y, 0); Vector3 moveDirection = head; if (moveDirection != Vector3.zero) { float angle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg; if (angle < 0) { angle = -1 * Mathf.Abs(Mathf.RoundToInt(angle)) / 90 * 90; } else { angle = Mathf.RoundToInt(angle) / 90 * 90; } transform.rotation = Quaternion.AngleAxis(angle, Vector3.up); } dir = onIndex.outputPortal.getHeading(); if (dir == Vector2.left) { transform.rotation = new Quaternion(0, 0, 0, 1); } if (dir == Vector2.right) { transform.rotation = new Quaternion(0, 1, 0, 0); } if (dir == Vector2.down) { transform.rotation = new Quaternion(1, 1, 0, 0); } if (dir == Vector2.up) { transform.rotation = new Quaternion(1, -1, 0, 0); } //Debug.Log(transform.rotation); transform.position = onIndex.outputPortal.getPosition(); Move(); PortalToDelete local = new PortalToDelete(); local.setInputPortal(coll.gameObject); local.setOutPortal(onIndex.outputPortal.getOutputPortal()); local.numberOfSteps = 0; } } else if (coll.name.StartsWith(AddPortalSript.backgroundOut.name)) { gameOver(); } else if (coll.name.StartsWith(finalPOrtalGameObject.name)) { desiredLengthOfSnake += 6; if (nextLevel < 4) { Loading.unlockLevel(nextLevel); } SetLevel(nextLevel); finalPortalOpen = false; UpdateSpeed(true); } else if (coll.name.StartsWith(toPortalBobyPieceGO.name)) { } else { Loading.setScore(Loading.getLastLevelId(), score); gameOver(); score = 0; scoreText.text = score.ToString(); // ToDo 'You lose' screen //Debug.Log("collision with: " + coll.name); //Debug.Log("Score: " + tail.Count); //initialize(); } }