private void spawnThis(GameObject toSpawn, bool Enemy) { if (Enemy) { GameObject _spawnedRodent = GameObject.Instantiate(toSpawn, _spawnLoc, this.transform.rotation); //parent this to keep hierarchy clean if (_EnemySpawnDummy) { _spawnedRodent.transform.SetParent(_EnemySpawnDummy); } else { Debug.LogWarning("No Enemy Dummy for Hierarchy"); } // Tag becoming obsolete _spawnedRodent.tag = "EnemyRodent"; // Ensure Sprite is enemy Rodent r = _spawnedRodent.GetComponent <Rodent>(); if (r) { r.setTeam(2); SubjectScript ss = r.GetComponent <SubjectScript>(); if (ss) { ss.setDefender(); StartCoroutine(RoyalGuardDelay(ss)); } // Force them to be aggressive and head toward player //hack if (_inPlayerZone) { r.setTargetEnemyVersion(GameManager.Instance.getTownCenter().gameObject); } } // Increase some kind of count --_EnemyCount; if (_EnemyCount == 0) { _occupied = true; } } else { _occupied = true; GameObject _spawnedRat = GameObject.Instantiate(toSpawn, _spawnLoc, this.transform.rotation); //parent this thing to this obj keep hierarchy cleaner? Might end up negatively affecting the subject Script? _spawnedRat.transform.SetParent(this.transform); // Tag becoming obsolete _spawnedRat.tag = "NeutralRodent"; // Ensure Sprite is Neutral _spawnedRat.GetComponent <Rodent>().setTeam(0); // Increase some kind of count } }
/** Responsible for giving SubjectScript new Target and Updating our Status */ public void setTarget(GameObject o) { //print("set Target called"); _placeOfWork = o; //need proper getter/setter someday SubjectScript s = this.GetComponent <SubjectScript>(); if (s) { s.changeTarget(o); } if (o == null) { _Status = eStatus.Available; s.setIdle(); //Show the Exclamation for available non enemy rodents if (_Team != 2) { _NotificationObject.SetActive(true); _NotifyAnimator.SetBool("Notify", true); } return; } if (o.GetComponent <BuildableObject>()) { BuildableObject bo = o.GetComponent <BuildableObject>(); if (bo.getState() == BuildableObject.BuildingState.Building) { //Tell subject script to behave like a builder s.setBuilder(); _Status = eStatus.Building; _NotificationObject.SetActive(false); // Debug.Log("Updated State to Builder"); //OR // Tell them to defend a location when that script arrives // _Status = eStatus.Army; } else if (bo.getState() == BuildableObject.BuildingState.Built || bo.getState() == BuildableObject.BuildingState.Idle) { //Unknown if state IDLE could cause a unique problem, can a building be // idle but not built? i forget _NotificationObject.SetActive(false); // Tell Subject Script to behave like a Worker if (bo.getType() == BuildableObject.BuildingType.Outpost) { _Status = eStatus.Army; // for all intensive purposes army can behave same for player and defense structure s.setDefender(); // print("Told to be defender"); } else if (bo.getType() == BuildableObject.BuildingType.Farm) { _Status = eStatus.Working; s.setFarmer(); } else { _Status = eStatus.Working; s.setGatherer(); } } } else if (o.GetComponent <PlayerStats>()) { //Debug.Log("Was told to go to RoyalGuard"); // Tell Subject script to behave like a bodyguard _NotificationObject.SetActive(false); s.setRoyalGuard(); _Status = eStatus.Army; // for all intensive purposes army can behave same for player and defense structure } else { Debug.Log("We dont know this behavior"); s.setIdle(); } }
IEnumerator RoyalGuardDelay(SubjectScript ss) { yield return(new WaitForSeconds(2f)); ss.setDefender(); }