private void CheckDistance(GameObject obj, float dist, bool controllerType) { if (Vector3.Distance(transform.position, obj.transform.position) <= dist && controllerType) { HeroController hCtrl = obj.GetComponent <HeroController>(); if (Vector3.Distance(transform.position, obj.transform.position) <= dist && controllerType) { if (CardColor.Equals("red")) { hCtrl.HasRedKeyCard = true; } if (CardColor.Equals("blue")) { hCtrl.HasBlueKeyCard = true; } } hCtrl.PlayKeyCardAudio(); Destroy(this.gameObject); } if (Vector3.Distance(transform.position, obj.transform.position) <= dist && !controllerType) { DummyController dCtrl = obj.GetComponent <DummyController>(); if (Vector3.Distance(transform.position, obj.transform.position) <= dist && !controllerType) { if (CardColor.Equals("red")) { dCtrl.HasRedKeyCard = true; } if (CardColor.Equals("blue")) { dCtrl.HasBlueKeyCard = true; } } dCtrl.PlayKeyCardAudio(); Destroy(this.gameObject); } if (Vector3.Distance(transform.position, obj.transform.position) <= dist && !controllerType && !spider.GetComponent <SpiderController>().destroyFlag) { SpiderController sCtrl = obj.GetComponent <SpiderController>(); if (CardColor.Equals("red")) { sCtrl.HasRedKeyCard = true; } if (CardColor.Equals("blue")) { sCtrl.HasBlueKeyCard = true; } sCtrl.PlayKeyCardAudio(); Destroy(this.gameObject); } }