IEnumerator chargePusher(Vector3 newPos) { RaycastHit hit; Vector3 chargDir = transform.position - newPos; if (unitAttached != null) { unitAttached.moving = true; while (unitAttached.moving) { Debug.DrawRay(transform.position, -chargDir.normalized * 10f, Color.blue); if (Physics.Raycast(transform.position, -chargDir.normalized, out hit, 1f)) { if (hit.collider.tag == "Player") { TBSUnit tmpUnit = hit.collider.GetComponent <TBSUnit>(); if (tmpUnit.whoOwnsMe() != ownerInt) { tmpUnit.Pushed(newPos, chargDir); } } else if (hit.collider.tag == "aiPlayer") { AIUnit tmpAIUnit = hit.collider.GetComponent <AIUnit>(); if (tmpAIUnit.whoOwnsMe() != ownerInt) { tmpAIUnit.Pushed(newPos, chargDir); } } else if (hit.collider.tag == "Pushable") { hit.collider.GetComponent <Pushable>().Pushed(newPos, chargDir); } } yield return(null); //Check next frame but wait until then } yield return(null); } else { AIUnit unitTmp = gameObject.GetComponent <AIUnit>(); unitTmp.moving = true; while (unitTmp.moving) { Debug.DrawRay(transform.position, -chargDir.normalized * 1f, Color.black); if (Physics.Raycast(transform.position, -chargDir.normalized, out hit, 1f)) { //Debug.Log(hit.collider.name); if (hit.collider.tag == "Player") { TBSUnit tmpUnit = hit.collider.GetComponent <TBSUnit>(); if (tmpUnit.whoOwnsMe() != ownerInt) { hit.collider.GetComponent <TBSUnit>().Pushed(newPos, chargDir); } } else if (hit.collider.tag == "Pushable") { hit.collider.GetComponent <Pushable>().Pushed(newPos, chargDir); } } yield return(null); //Check next frame but wait until then } yield return(null); } }