public override void OnIndexTriggered() { base.OnIndexTriggered(); if (!startSelected) { startSelected = true; Debug.Log("Raycast Initated"); RaycastHit hit; GameObject hitObject = null; if (Physics.Raycast(pointer.transform.position, pointer.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity)) { hitObject = InitRayCast(hit); } if (selectedConstruct != null) { if (selectedConstruct.IsBuildable()) { selectedConstruct.ConfirmBuild(); selectedConstruct = null; } } else { CheckUnitOBJ(hitObject); CheckUIOBJ(hitObject); } EtherDeposit eth = hitObject.GetComponent <EtherDeposit>(); if (selectedWorker != null && eth != null) { selectedWorker.GoHarvest(eth); } if (hitObject.tag == "Terrain" && (selectedUnit != null || selectedWorker != null)) { UnitMove mover = null; if (selectedUnit != null) { mover = selectedUnit.GetComponent <UnitMove>(); selectedUnit.SetAutoAttaack(false); selectedUnit.SetTarget(null); } else if (selectedWorker != null) { mover = selectedWorker.GetComponent <UnitMove>(); selectedWorker.GoHarvest(null); } mover.OrderMove(hit.point); StartCoroutine(MovePointIndicator(hit.point)); } } }
// Update is called once per frame void Update() { armyCoolNow -= Time.deltaTime; actionCool -= Time.deltaTime; if (actionCool <= 0) { actionCool = 5; Debug.Log("AI " + playerStat.GetPlayerNumber() + " have worker : " + workerList.Count); int playerNum = playerStat.GetPlayerNumber(); if (!aiStronghold) { Debug.Log("AI " + playerStat.GetPlayerNumber() + " find stronghold."); BuildingSystem[] bui = FindObjectsOfType <BuildingSystem>(); foreach (BuildingSystem buiDum in bui) { ConstructSystem con = buiDum.GetComponent <ConstructSystem>(); if (con && buiDum.GetOwner() == playerNum) { aiStronghold = buiDum; } } } else { CheckStronghold(); } if (aiBarrack) { CheckBarrack(); } if (aiStable) { CheckStable(); } } if (armyList.Count > 0 && armyCoolNow <= 0) { CheckArmy(); armyCoolNow = armyAICool; } WorkerUnit[] wor = FindObjectsOfType <WorkerUnit>(); foreach (WorkerUnit workerDum in wor) { if (workerDum.GetOwner() == playerStat.GetPlayerNumber() && !workerList.Contains(workerDum)) { etherClose.Clear(); Collider[] hitColliders = Physics.OverlapSphere(aiStronghold.transform.position, 30); int i = 0; while (i < hitColliders.Length) { EtherDeposit etherOBJ = hitColliders[i].GetComponent <EtherDeposit>(); if (etherOBJ) { etherClose.Add(etherOBJ); } i++; } if (etherClose.Count > 0) { EtherDeposit etherTarget = etherClose[Random.Range(0, etherClose.Count)].GetComponent <EtherDeposit>(); workerDum.GoHarvest(etherTarget); workerList.Add(workerDum); } } } }
public void GoHarvest(EtherDeposit ethe) { etherTarget = ethe; }