// Update is called once per frame void Update() { // Create a list that will store points on the collision-detection circle around the cannonball List <int[]> points = new List <int[]>(); // Get the current x and y positions of the cannonball as integers (the center point of the cannonball) and add it to the points list int[] centerPoint = new int[2] { (int)transform.position.x, (int)transform.position.y }; points.Add(centerPoint); // Compute the left, right , top, and bottom points of the collision-detection circle around the cannonball points.Add(new int[2] { centerPoint[0] - collisionRadius, centerPoint[1] }); // Left point points.Add(new int[2] { centerPoint[0] + collisionRadius, centerPoint[1] }); // Right point points.Add(new int[2] { centerPoint[0], centerPoint[1] + collisionRadius }); // Top point points.Add(new int[2] { centerPoint[0], centerPoint[1] - collisionRadius }); // Bottom point // Detect collision with water if (collisionWithWater(points)) { Destroy(gameObject); // The cannonball disappears return; // End script } // Detect collision with ground if (collisionWithGround(points)) { // The cannonball bounces cannonballMotion.Bounce(centerPoint[0], centerPoint[1]); } }