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 } }
void Awake() { ssr = options.GetComponent <ScrollSnapRect>(); XDocument classdoc = XDocument.Parse(classes.text); List <Node> units = LoadUnits(classdoc.Descendants("Units").Elements("Unit")); //DebugTree(units); //check = units; SubjectScript ss = layers[0].GetComponent <SubjectScript>(); ss.Check(units[0]); }
//Have to do a delay otherwise subject script settings get really messed up IEnumerator attackerDelay(GameObject o) { yield return(new WaitForSeconds(0.8f)); SubjectScript s = this.GetComponent <SubjectScript>(); if (s) { s.changeTarget(o); } s.setAttacker(); _Status = eStatus.Army; }
// Start is called before the first frame update void Start() { if (_HealthBarObj == null) { _HealthBarObj = Resources.Load <GameObject>("UI/HealthBarCanvas"); } SetUpHealthBar(_HealthBarObj.gameObject); SetUpRecruitMenu(); _SubjectScript = this.GetComponent <SubjectScript>(); if (_SubjectScript == null) { Debug.LogError("Warning No SubjectScript found for Rodent"); } setTeam(_Team); //get a name _Name = RodentNames.getRandomName(); //Add Day/Night Cycle Stuff SetUpDayNight(); setUpNotifyObj(); if (_Status != eStatus.Army) // if spawned from invasion will have status set already { setTarget(null); } _ID = GameManager.Instance.getRodentIdex(); // Debug.Log(this.gameObject + " ID is: " + _ID); GameManager.Instance.AddtoRodents(this); //Rename Prefab if (_Type != eRodentType.EKing) { this.gameObject.name = _ID + " Rodent: " + _Name + " "; } _isRanged = PickRanged(); if (_Team == 2) { _NotificationObject.SetActive(false); this.GetComponent <Animator>().SetBool("isArmed", true); } }
public void Whichlayer() { int index = ssr._currentPage + 1; GameObject block = blocks[index - 1]; block.GetComponentInChildren <Text>().text = selected.Name; GameObject layer = layers[index]; layer.SetActive(false); //Debug.Log(layer.name); SubjectScript ss = layer.GetComponent <SubjectScript>(); ss.Check(selected); layer.SetActive(true); }
/** 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(); }
// Start is called before the first frame update void Start() { _range = this.GetComponent <BoxCollider2D>(); _subjectScript = transform.parent.GetComponent <SubjectScript>(); }