public void ActivateObject() { boxCollider.enabled = true; navMeshObstacle.enabled = true; interactable.enabled = true; buildState = BUILDSTATE.NOT_BUILT; }
public void SetBuilding() { b_state = BUILDSTATE.B_CONSTRUCT; buildTimerTemp.enabled = true; PlayAudio.instance.m_source.clip = PlayAudio.instance.m_construct; PlayAudio.instance.m_source.Play(); PlayAudio.instance.m_source.volume = 0.1f; PlayAudio.instance.m_source.priority = 1; PlayAudio.instance.m_soundOwner = gameObject; }
public void SetBuildState(BUILDSTATE _state) { buildState = _state; }
private void Construction() { switch (buildState) { case BUILDSTATE.PLACING: break; case BUILDSTATE.NOT_BUILT: if (meshFilter.mesh != foundationMesh) { meshFilter.mesh = foundationMesh; } buildTimer += Time.deltaTime; buildtimerForeground.fillAmount = buildTimer / buildTime; if (buildTimer > (buildTime / 2)) { buildState = BUILDSTATE.BUILDING; if (meshFilter) { meshFilter.mesh = constructionMesh; } } break; case BUILDSTATE.BUILDING: if (meshFilter.mesh != constructionMesh) { meshFilter.mesh = constructionMesh; } buildTimer += Time.deltaTime; buildtimerForeground.fillAmount = buildTimer / buildTime; if (buildTimer > buildTime) { if (increasePopulation) { if (!enemyBuilding) { playerManager.NewHouse(); } else { aiManager.NewHouse(); } } if (collector) { GetComponent <ResourceCollection>().enabled = true; } buildState = BUILDSTATE.FINISHED; if (meshFilter) { meshFilter.mesh = finishedMesh; } } break; case BUILDSTATE.FINISHED: if (meshFilter.mesh != finishedMesh) { meshFilter.mesh = finishedMesh; buildtimerBackground.enabled = false; buildtimerForeground.enabled = false; built = true; } return; } }
// Update is called once per frame void Update() { switch (b_state) { case BUILDSTATE.B_HOLOGRAM: for (int i = 0; i < gameObject.transform.GetChild(0).childCount; ++i) { gameObject.transform.GetChild(0).transform.GetChild(i).GetComponent <MeshRenderer>().material = holo; } break; case BUILDSTATE.B_CONSTRUCT: timerB += Time.deltaTime; if (timerB < buildTimer) { if (buildingTemp) { buildingTemp.Play(); buildingTemp.transform.position = gameObject.transform.position; buildTimerTemp.fillAmount += 1.0f / buildTimer * Time.deltaTime; buildTimerTemp.transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position); for (int i = 0; i < gameObject.transform.GetChild(0).childCount; ++i) { gameObject.transform.GetChild(0).transform.GetChild(i).GetComponent <MeshRenderer>().material = holo; } } } else if (timerB >= buildTimer) { if (buildingTemp) { buildingTemp.Stop(); buildingTemp.transform.position = gameObject.transform.position; for (int i = 0; i < gameObject.transform.GetChild(0).childCount; ++i) { gameObject.transform.GetChild(0).transform.GetChild(i).GetComponent <MeshRenderer>().material = undamaged; } b_state = BUILDSTATE.B_ACTIVE; buildingHealthImage.enabled = true; buildingHealthImage.transform.GetChild(0).GetComponent <Image>().enabled = true; GetComponent <Spawn>().SetSpawnPosition(); Destroy(buildingTemp); Destroy(buildTimerTemp); } } break; case BUILDSTATE.B_ACTIVE: if (PlayAudio.instance.m_soundOwner != null) { if (PlayAudio.instance.m_source.isPlaying && PlayAudio.instance.m_soundOwner.Equals(gameObject) && PlayAudio.instance.m_source.time > buildTimer) { PlayAudio.instance.m_source.Stop(); } } if (buildingHealthImage != null) { buildingHealthImage.transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position + gameObject.transform.up.normalized * 10); buildingHealthImage.transform.GetChild(0).GetComponent <Image>().fillAmount = buildingHealth / maxBuildingHealth; buildingHealthImage.transform.GetChild(0).GetComponent <Image>().transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position + gameObject.transform.up.normalized * 10); } if (GetComponent <Spawn>() && spawnTimerTemp) { if (isfriendly) { spawnTimerTemp.enabled = true; } spawnTimerTemp.fillAmount = GetComponent <Spawn>().GetRatio(); spawnTimerTemp.transform.position = Camera.main.WorldToScreenPoint(gameObject.transform.position); } for (int i = 0; i < gameObject.transform.GetChild(0).childCount; ++i) { gameObject.transform.GetChild(0).transform.GetChild(i).GetComponent <MeshRenderer>().material = undamaged; } if (!m_isDistract) { if (isfriendly && GetComponent <Pathfinder>() && LevelManager.instance.EnemyBase) { GetComponent <Pathfinder>().FindPath(GetComponent <Spawn>().UnitSpawnPosition, GetMaxPosOfBuilding(LevelManager.instance.EnemyBase.transform.position, LevelManager.instance.EnemyBase.GetComponent <Building>().size)); } else if (!isfriendly && GetComponent <Pathfinder>() && LevelManager.instance.PlayerBase) { GetComponent <Pathfinder>().FindPath(GetComponent <Spawn>().UnitSpawnPosition, GetMaxPosOfBuilding(LevelManager.instance.PlayerBase.transform.position, LevelManager.instance.PlayerBase.GetComponent <Building>().size)); } } //if (GetComponent<Health>().GetHealth() < 0) //{ // Unit.m_destroyerOfWorlds = new Component[100]; // Unit.RemoveEntity(gameObject, m_buildingList); // UnityEngine.Object.Destroy(this.gameObject); // //Unit.m_destroyerOfWorlds = GetComponents(typeof(Component)); // //for (int i = 0; i < Unit.m_destroyerOfWorlds.Length; ++i) // //{ // // if (Unit.m_destroyerOfWorlds[i].gameObject.activeSelf) // // UnityEngine.Object.Destroy(Unit.m_destroyerOfWorlds[i]); // //} //} break; } }