public void DestroyPiece() { if (GetComponent <Snake>()) { Destroy(transform.parent.gameObject); return; } if (nextPiece) { nextPiece.DestroyPiece(); } Destroy(gameObject); }
void CheckForCollisions() { for (int i = 0; i < SnakeManager.snakeList.Count; ++i) { if (SnakeManager.snakeList[i] != this) { SnakePiece piece = SnakeManager.snakeList[i].CheckForCollision(transform.position); if (piece) { if (chargeCounter > 0.0f) { piece.DestroyPiece(); } } } } }
// Update is called once per frame void Update() { transform.Translate(m_MoveDirection * 0.5f); if (transform.position.y > Snake.maxY || transform.position.y < Snake.minY || transform.position.x > Snake.maxX || transform.position.x < Snake.minX) { Destroy(gameObject); return; } for (int i = 0; i < SnakeManager.snakeList.Count; ++i) { SnakePiece piece = SnakeManager.snakeList[i].CheckForCollision(transform.position); if (piece) { piece.DestroyPiece(); Destroy(gameObject); } } }