public void NPCDie(GameEntities.NPCs.NPC npc, Wave wave) { wave.npcs.Remove(npc.gameObject); if (wave.npcs.Count == 0) { NPCs.Remove(wave); } }
private IEnumerator MovementNpcX(Wave wave, GameObject npc, Vector3 dstPos, int listIndex, float sign) { yield return(new WaitForSeconds(MovementData.npcMoveTime * listIndex * MovementData.waitBeforeMoveNextNpc)); Vector3 startPos = npc.transform.position; GameEntities.NPCs.NPC npcC = npc.GetComponent <GameEntities.NPCs.NPC>(); npcC.StartMove(); float startMove = 0.5f; // percent value float endMove = 0.4f; // percent value float moveDuration = (1f - startMove) * MovementData.npcMoveTime + endMove * MovementData.npcMoveTime; yield return(npcC.StartCoroutine(OnWayMovementNpcX(npc, startPos, dstPos, sign, startMove, 1, 0, moveDuration, false))); yield return(npcC.StartCoroutine(OnWayMovementNpcX(npc, startPos, dstPos, sign, -1, endMove, (1f - startMove) * MovementData.npcMoveTime, moveDuration, true))); npcC.EndMove(); }
private IEnumerator OnWayMovementNpcX(GameObject npc, Vector3 startPos, Vector3 dstPos, float sign, float startMove, float endMove, float moveTime, float moveDuration, bool oppositeProgress) { float curTime = 0; GameEntities.NPCs.NPC npcC = npc.GetComponent <GameEntities.NPCs.NPC>(); while (curTime < MovementData.npcMoveTime) { curTime += Time.deltaTime; float oneWayIntensity = curTime / (MovementData.npcMoveTime * 2); float signedIntensity = curTime / MovementData.npcMoveTime; if (oppositeProgress) { signedIntensity = 1f - signedIntensity; } if (oppositeProgress) { oneWayIntensity += 0.5f; } npcC.Rotate(signedIntensity * sign, oneWayIntensity); if (curTime >= startMove * MovementData.npcMoveTime && curTime <= endMove * MovementData.npcMoveTime) { moveTime += Time.deltaTime; Vector3 tgtPos = dstPos; tgtPos.y = npc.transform.position.y; tgtPos.x = Mathf.Lerp(startPos.x, dstPos.x, moveTime / moveDuration); npc.transform.position = tgtPos; } yield return(new WaitForEndOfFrame()); } Vector3 tgtPos2 = dstPos; tgtPos2.y = npc.transform.position.y; npc.transform.position = tgtPos2; }