// Handle collision public void OnTriggerEnter2D(Collider2D collision) { NumberNode otherNode = collision.GetComponent <NumberNode>(); if (otherNode != null) { // Prevent collision with Preview nodes if (otherNode.state == NodeState.PREVIEW || this.state == NodeState.PREVIEW) { return; } // Prevent collision detection with other nodes in gutter if (NodeManager.Contains(otherNode)) { return; } // Collision happened between this node and the other node, // where this node is in the gutter and the other node is in a projectile state // So place said the other node into the gutter at the place of this node. // Also disable the node motor since it will no longer be used in the gutter. otherNode.nodeMotor.enabled = false; NodeManager.InsertAtPlaceOf(NodeManager.GetNodes().Find(this), otherNode); GameStateManager.SwitchToDispersing(); } }
// Destroys dead nodes from the NodeManager public void DestroyDeadNodes() { List <NumberNode> nodesToDestroy = new List <NumberNode>(); // Loop over each node and mark them for destruction foreach (NumberNode node in NodeManager.GetNodes()) { // If node is dead if (!node.alive) { // Mark node eligible for destruction nodesToDestroy.Add(node); ParticlesList.Add(node.transform.position); ScoreAdd.AddScore(10); nodeDestroyedAudio.ShouldPlay = true; } else { // If node is alive, but has reached the end of the gutter if (node.pathFollower.distanceTravelled >= node.pathFollower.pathCreator.path.length) { // Mark node eligible for destruction nodesToDestroy.Add(node); screenShake.CamShake(); healthController.RemoveLife(); GameStateManager.SwitchToMoveBack(); } } } // Destroy nodes that are eligible for destruction // (Do this afterwards to not mess with the array during the foreach loop) foreach (NumberNode node in nodesToDestroy) { ScoreAdd.SetFurthestDistanceTravelled(node.pathFollower.distanceTravelled); NodeManager.RemoveNode(node); Destroy(node.gameObject); } }