private void OnTriggerEnter(Collider collision) { if (collision.gameObject.CompareTag("NonPlayerBall")) { Sphere ball = collision.GetComponentInParent <Sphere>(); score += Math.Round(ball.mass, 2) + Math.Round(ball.radius, 2); MasterObserver.updateSpheresList(); Destroy(collision.gameObject); } }
void Update() { velocity += acceleration * Time.deltaTime; transform.position += velocity * Time.deltaTime; foreach (Plane plane in planes) { Vector3 fromPlaneToSphere = transform.position - plane.transform.position; Vector3 planeNormal = plane.normal; if (parallel(fromPlaneToSphere, planeNormal).magnitude < radius) { velocity = collideWithPlane(plane); } } foreach (Sphere otherSphere in sphereList) { if (otherSphere == null) { sphereList.Remove(otherSphere); MasterObserver.updateSpheresList(); } else if (otherSphere != this) { Vector3 fromThisToOtherSphere = transform.position - otherSphere.transform.position; if (fromThisToOtherSphere.magnitude < radius + otherSphere.radius) { collideWithSphere(otherSphere); } } } float score; velocity -= velocity * 0.01f; }