void Update() { //in a normal game, there will be many different types of objects in a scene // this foreach loop looks through all the game objects and if it finds one with ZombieData component // then it adds some data. foreach (GameObject go in gos) { ZombieData zd = (ZombieData)go.GetComponent(typeof(ZombieData)); // Zombie data class is assigned to the variable zd if (zd == null) // if the game Object does not have any ZombieData, then zd will not be assigned anything, it remains null { continue; // go back to the top of loop, and move on to the next item in the array. } if (zd.hitpoints > 0) { break; } print(go.name); zd.hitpoints = 10; // // - check to see if a gameObject has the Human Data Component component, if it does add it to an Array List // // called allHumans, and then continue to the next object in the list. // HumanData hd = (HumanData)go.GetComponent(typeof(HumanData)); // if (hd != null) // { // allHumans.Add (go); // continue; // } } }
public void Start() { GameObject zombie = this.gameObject; ZombieData zombieData = new ZombieData(); zombie.transform.position = new Vector3(Random.Range(-20, 21), 0, Random.Range(-20, 21)); Renderer zRender = zombie.GetComponent <Renderer>(); int numeroColor = Random.Range(0, 3); if (numeroColor == 0) { zRender.material.color = Color.cyan; } else if (numeroColor == 1) { zRender.material.color = Color.green; } else { zRender.material.color = Color.magenta; } Gusto enumGusto; enumGusto = (Gusto)Random.Range(0, (int)Gusto.lenght); gusto = enumGusto.ToString(); zombieData.Gusto = gusto; zombie.AddComponent <ZombieCollision>().TakeData(zombieData); zombie.AddComponent <ZombieStatus>(); }
/// <summary> /// Message this instance. /// Check if the "Hero" is near an NPC. /// </summary> void Message() { if (!isDead) { foreach (GameObject other in npc) { if (other) { Vector3 offset = other.transform.position - hero.transform.position; float sqrLen = offset.sqrMagnitude; if (sqrLen < closeDistance * closeDistance) { if (other.GetComponent <Citizen>()) //Condition (If I collide with an object with the component "Citizen"). { _citizenData = other.GetComponent <Citizen>().CitizenID(); //Assigns the citizen's information to use in the message. panelUI.SetActive(true); textTypeName.text = ("Citizen"); textDialogue.text = ("Hello I am " + _citizenData.name + " and I have " + _citizenData.age + " years old"); //Message given by the citizen when making contact. StartCoroutine(EnablePanel()); } if (other.GetComponent <Zombie>()) //condition (If I collide with an object with the component "Zombie"). { _zombieData = other.GetComponent <Zombie>().ZombieID(); //Assigns the zombie information to use in the message. panelUI.SetActive(true); textTypeName.text = ("Zombie"); textDialogue.text = ("Waaaaarrrr I want to eat " + _zombieData._taste); //Message given by the zombie when he comes into contact. StartCoroutine(EnablePanel()); } } } } } }
protected virtual void OnEnable() { controller = GetComponent <ZombieCtrl>(); zombieData = controller.zombieData; behavior = GetComponent <ZombieBehavior>(); behavior.AddStateReceiver(StateChanged); }
/// <summary> /// Se encarga de dar una estructura de zombie a un aldeano para transformalo /// </summary> /// <returns> /// Estrucutra de aldeano para conversion /// </returns> public ZombieData GetData() { ZombieData newzombieData = new ZombieData(); newzombieData.edad = edad; newzombieData.gusto = gusto; return(newzombieData); }
void Start() { inCrazy = false; animator = GetComponent <Animator>(); movePlug = new CorePlugMoveByDict(this, gameObject); movePlug.moveSpeed = _moveSpeed; _roleData = data = new ZombieData(); playerCtl = player.GetComponent <PlayerControl>(); }
void Awake() { m_Nav = GetComponent <NavMeshAgent>(); m_Data = GetComponent <ZombieData>(); m_Ani = GetComponent <Animator>(); body_col = obj_body.GetComponent <BoxCollider>(); head_col = obj_head.GetComponent <BoxCollider>(); }
public void addZombie(ZombieData zombie, Vector2 _spawnLocation) { NightGameEngineImp.getGameEngine().getSoundManager().playZombieSound(); Vector2 spawnLocation = _spawnLocation; while (NightGameEngineImp.getGameEngine().getMapManager().getWorldCollision(spawnLocation) >= 0) { spawnLocation = new Vector2(random.Next(-500, 1600), random.Next(-300, 1000)); } zombie.setCurrentLocation(spawnLocation); Zombies.Add(zombie); }
void ClearOldZombies() { for (int i = 0; i < _zombies.Count; ++i) { ZombieData currZombieData = _zombies[i]; if ((currZombieData.AddedTime - Time.timeSinceLevelLoad) < _timeToCleanHItted) { _zombies.RemoveAt(i); } } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Zombie") { ZombieData zombieData = collision.gameObject.GetComponent <Enemy.GenerarZombie>().zombieData; Debug.Log("Waaaaaarrr quiero comer" + zombieData.Gusto); } if (collision.gameObject.tag == "Aldeano") { VillagerData villagerData = collision.gameObject.GetComponent <Ally.GenerarAldeano>().villagerData; Debug.Log("Hola mi nombre es " + villagerData.name + " y tengo " + villagerData.Age + " años"); } }
bool CheckzombieWasOverwelmed(Zombie zombie) { for (int i = 0; i < _zombies.Count; ++i) { ZombieData currZombieData = _zombies[i]; if (currZombieData.Zombie == zombie) { return(true); } } return(false); }
/// <summary> /// Se encarga de detectar la distancia con aldeanos y zombies con el fin de mostrar informacion en UI de la entidad /// </summary> void Update() { aldeanos = GameObject.FindGameObjectsWithTag("Aldeano"); zombies = GameObject.FindGameObjectsWithTag("Zombie"); timer1 += Time.deltaTime; timer2 += Time.deltaTime; timer3 += Time.deltaTime; disparoDebug.maxValue = cd; disparoDebug.value = timer3; if (timer3 > cd) { if (Input.GetKeyDown(KeyCode.Space)) { Disparar(); timer3 = 0; } } foreach (GameObject aldeano in aldeanos) { distanciaAldeano = Mathf.Sqrt(Mathf.Pow((aldeano.transform.position.x - transform.position.x), 2) + Mathf.Pow((aldeano.transform.position.y - transform.position.y), 2) + Mathf.Pow((aldeano.transform.position.z - transform.position.z), 2)); if (distanciaAldeano < 5f) { timer1 = 0; VillagerData villagerData = aldeano.GetComponent <Aldeano.AldeanoScript>().GetData(); textAldeano.text = "Hola soy " + villagerData.nombre + " y tengo " + villagerData.edad; } } foreach (GameObject zombie in zombies) { distanciaZombie = Mathf.Sqrt(Mathf.Pow((zombie.transform.position.x - transform.position.x), 2) + Mathf.Pow((zombie.transform.position.y - transform.position.y), 2) + Mathf.Pow((zombie.transform.position.z - transform.position.z), 2)); if (distanciaZombie < 5f) { timer2 = 0; ZombieData zombieData = zombie.GetComponent <Zombie.ZombieScript>().GetData(); textZombie.text = "Wraaaaarr quiero " + zombieData.gusto; } } if (timer1 > 5f) { textAldeano.text = ""; } if (timer1 > 5f) { textZombie.text = ""; } }
void Update() { foreach (GameObject go in gos) { ZombieData zd = ( ZombieData )go.GetComponent(typeof(ZombieData)); if (zd == null) { continue; } if (zd.hitpoints > 0) { break; } print(go.name); zd.hitpoints = 10; } }
private void Update() { data = dataZ; //se encuentran los objetos de la escena y se guardan en una matriz para luego elegir cual es el heroe GameObject[] allGameObjects = FindObjectsOfType(typeof(GameObject)) as GameObject[]; foreach (GameObject hGameObject in allGameObjects) { Component hComponent = hGameObject.GetComponent(typeof(Heroe)); if (hComponent != null) { player = hGameObject; } } //se busca el aldeano más cercano float minDistance = 5; Villager villager = null; foreach (var v in FindObjectsOfType <Villager>()) { if (Vector3.Distance(transform.position, v.gameObject.transform.position) < minDistance && v.gameObject.transform.tag == "Villager") { villager = v; } } // se cambia elcolor si el juego se acaba if (Generator.gameOver == true) { GetComponent <Renderer>().material.color = (Color.red); } //se busca la dirección y la distancia del heroe direction = Vector3.Normalize(player.transform.position - transform.position); distance = (player.transform.position - transform.position).magnitude; //se busca la dirección y la distancia del aldeano que esté en una distancia menor o igual a minDistance if (villager) { vDirection = Vector3.Normalize(villager.transform.position - transform.position); vDistance = (villager.transform.position - transform.position).magnitude; } // se decide si la distancia del heroe es menor a 5 y si no hay ningun aldeano, para proceder a perseguir al heroe //si hay aldeanos cerca persigue al aldeano antes que al heroe if (Generator.game == true) { if (Generator.gameOver == false && distance <= 5 && villager == null) { transform.position += direction * baseSpeed * Time.deltaTime; data.comportZomb = BasicIA.Pursuing; } else if (vDistance <= 5) { transform.position += vDirection * baseSpeed * Time.deltaTime; data.comportZomb = BasicIA.Pursuing; } MovimentNPCs(); } }
// Use this for initialization void Awake() { m_Ani = GetComponent <Animator>(); m_AI = GetComponent <DevilZombieAI>(); m_Data = GetComponent <ZombieData>(); }
IEnumerator RunTurret() { while (true) { // find target List <Transform> activeEnemies = new List <Transform>(); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject o in enemies) { if (o.activeSelf && o.gameObject.name.Contains("Zombie")) { activeEnemies.Add(o.transform); } } if (activeEnemies.Count == 0) { yield return(new WaitForSeconds(1f)); continue; } Transform closestEnemy = GetClosestEnemy(activeEnemies.ToArray(), 26f); if (closestEnemy == null) { yield return(new WaitForSeconds(1f)); continue; } ZombieData zombieData = closestEnemy.GetComponent <ZombieData>(); if (zombieData == null) { yield return(new WaitForSeconds(1f)); continue; } // attack target until it dies while (zombieData.m_Hp != 0) { transform.LookAt(new Vector3(closestEnemy.position.x, Mathf.Max(1f, closestEnemy.position.y), closestEnemy.position.z)); fireTime -= Time.deltaTime; if (fireTime < 0f) { GameObject bullet = ObjectPoolMgr.instance.CreatePooledObject("Handgun_Bullet", transform.position, transform.rotation); bullet.SendMessage("SetBodyDamage", 20); bullet.SendMessage("SetHeadDamage", 40); AudioSource.PlayOneShot(AudioClip, VolumeHolderScript.instance.seVol); muzzleFlash.gameObject.SetActive(true); Invoke("TurnOffMuzzleFlash", 0.05f); fireTime += fireTimeConst; } yield return(new WaitForEndOfFrame()); } yield return(new WaitForSeconds(1f)); } }
public void Init(FSClient client) { var map = client.GetManager <RandomMapCreator>(); var playerPos = Fixed2.zero; if (map) { playerPos = map.GetRandomPos(); } else { playerPos = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20)); } int count = GameUser.user.fightRoom.playerInfos.Count; for (int i = 0; i < count; i++) { var player = new PlayerData(); player.Init(client, i); if (map != null) { player.transform.Position = playerPos + Fixed2.left * i.ToFixed(); } else { player.transform.Position = new IDG.Fixed2(0, i); } client.objectManager.Instantiate(player); } for (int i = 0; i < m_nItemCount; i++) { ItemData item; if (i % 2 == 0) { var Titem = new SkillItem(); item = Titem; Titem.Init(client); if (client.random.Range(0, 100) < 50) { Titem.skillId = SkillId.拳击右直; } else { Titem.skillId = SkillId.拳击左直; } } else { var Titem = new WeaponItem(); item = Titem; Titem.Init(client); Titem.weaponId = WeaponId.F57; } if (map) { item.transform.Position = map.GetRandomPos(); } else { item.transform.Position = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20)); } client.objectManager.Instantiate(item); } for (int i = 0; i < enemy; i++) { var item = new ZombieData(); item.Init(client); if (map) { item.transform.Position = map.GetRandomPos(); } else { item.transform.Position = new Fixed2(client.random.Range(0, 20), client.random.Range(0, 20)); } client.objectManager.Instantiate(item); } }
private void Awake() { m_Ani = GetComponent <Animator>(); m_Data = GetComponent <ZombieData>(); m_AI = GetComponent <RugbyZombieAI>(); }
public void TakeData(ZombieData zombieData) { zombieDat = zombieData; }
private bool m_CollidOnceCheck = false; //It prevent from damaging player twice private void Awake() { m_Data = gameObject.GetComponentInParent <ZombieData>(); m_Action = gameObject.GetComponentInParent <RugbyZombieAction>(); m_Col = GetComponent <BoxCollider>(); }