public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Collectable") { CollectableBlock cb = other.GetComponent <CollectableBlock>(); EventHandler <BlockGatheredEventInfo> handler = BlockGatheredEventHandler; if (handler != null) { handler(this, new BlockGatheredEventInfo(cb.type, cb.count)); } cb.Collect(); } else if (other.tag == "Ocean") { other.gameObject.GetComponent <Water>().GenerateSplash(transform.position, Math.Abs(Player.Velocity.y)); StartCoroutine(BobInSea(3f)); StartCoroutine(EndLevelAfterTime(3f)); } }
public void Init(CollectableBlock mb) { mainCamera = Camera.main; MarkingBlock = mb; SpriteRenderer mbSr = mb.gameObject.GetComponent <SpriteRenderer>(); MarkingBlockBounds = mbSr.bounds; m = new Material(mbSr.material); m.SetFloat("_DistanceBasedOpacity", 1f); spriteRenderer = gameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = mbSr.sprite; spriteRenderer.material = m; spriteRenderer.sortingLayerName = "UI"; spriteRenderer.sortingOrder = 1; transform.localScale = mb.transform.localScale; SetPositionAndDisplay(); }