public ArrayList LoseBots(int num, Transform destination) { ArrayList botsUsed = new ArrayList(); int numToUse = num; if (num > bots) { return(null); } for (int i = 0; i < totalBots.Count; i++) { GameObject bot = totalBots[i]; BotMovement botScript = bot.GetComponent <BotMovement>(); if (botScript.GetState() == BotMovement.BotMode.Follow || botScript.GetState() == BotMovement.BotMode.Stopped) { botScript.SetDest(destination); botScript.SetState(BotMovement.BotMode.Build); numToUse--; botsUsed.Add(i); if (numToUse == 0) { break; } } } bots -= num; overlayScript.setNumBots(bots); return(botsUsed); }
// Stop when colliding with another bot that's stopped private void BumpBot(BotMovement botScript) { if (botScript != null) { if (botScript.GetState() == BotMode.Stopped) { anim.SetBool("Walking", false); if (navMeshAgent.enabled) { navMeshAgent.isStopped = true; } botMode = BotMode.Stopped; bumpedBot = botScript; } } }
void Update() { if (navMeshAgent.isOnOffMeshLink && !jumping) { StartCoroutine(JumpOffMesh()); } if (botMode == BotMode.Follow) { if (navMeshAgent.enabled) { if (Vector3.Distance(FlattenTransform(followTarget.position), FlattenTransform(navMeshAgent.destination)) > 0.5f) { if (!navMeshAgent.pathPending) { navMeshAgent.SetDestination((followTarget.position)); } anim.SetBool("IsBlock", false); anim.SetBool("Walking", true); if (navMeshAgent.isStopped) { anim.SetBool("Walking", false); botMode = BotMode.Stopped; } } else if (navMeshAgent.remainingDistance <= 3f) { anim.SetBool("Walking", false); navMeshAgent.isStopped = true; botMode = BotMode.Stopped; } } } else if (botMode == BotMode.Stopped) { if (bumpedBot != null) { if (bumpedBot.GetState() != BotMode.Stopped) { bumpedBot = null; botMode = BotMode.Follow; } } else { if (Vector3.Distance(FlattenTransform(followTarget.position), FlattenTransform(navMeshAgent.destination)) > 0.5f) { navMeshAgent.isStopped = false; anim.SetBool("Walking", true); botMode = BotMode.Follow; } } } if (botMode == BotMode.Build) { if (!jumping) { if (!readyToBuild) { Collider[] colliders = gameObject.GetComponentsInChildren <Collider>(); foreach (Collider c in colliders) { c.enabled = false; } if (navMeshAgent.enabled) { navMeshAgent.isStopped = true; } StartCoroutine(JumpToBuild()); } else { readyToBuild = false; transform.gameObject.SetActive(false); } } } if (gameObject.activeSelf) { anim.SetFloat("Y", navMeshAgent.velocity.magnitude / navMeshAgent.speed); } }