/** * <summary> * On collides with any 2D game object * </summary> * * <returns> * void * </returns> */ protected virtual void OnCollisionEnter2D(Collision2D collision) { ShapeComponent shapeComponent = collision.transform.GetComponent <ShapeComponent>(); if (shapeComponent == null) { return; } // Is colliding with triangle if (shapeComponent is TriangleComponent) { this.spriteRenderer.color = Color.red; shapeComponent.WhatAmI(); } // Is colliding with circle else if (shapeComponent is CircleComponent) { this.spriteRenderer.color = Color.blue; shapeComponent.WhatAmI(); } // Is colliding with square else if (shapeComponent is SquareComponent) { this.spriteRenderer.color = Color.green; shapeComponent.WhatAmI(); } }