void Update() { GameObject go = GameObject.FindGameObjectWithTag("Player"); ally_targeting at = (ally_targeting)go.GetComponent("ally_targeting"); Enemy_health_tracking eh = (Enemy_health_tracking)GetComponent("Enemy_health_tracking"); if (timeSinceLastSpawn == 0) //New time { timeSinceLastSpawn = Time.time; //Set the current time } else { if (curEnemys.Count < maxNumberOfEnemys && (int)(Time.time - timeSinceLastSpawn) >= spawnDelay) { Instantiate(enemyToSpawn, spawnPlace, Quaternion.identity); at.targets = new List <Transform>(); curEnemys = new List <Transform>(); AddAllEnemy(); at.AddAllEnemy(); timeSinceLastSpawn = 0; } } if (eh.curHealth == 0) { curEnemys = new List <Transform>(); AddAllEnemy(); } //Debug.Log((int)(Time.time - timeSinceLastSpawn)); }
// Update is called once per frame void Update() { if (timer > 0) { timer -= Time.deltaTime; } if (timer < 0) { timer = 0; } if (Input.GetKeyDown(KeyCode.F)) { if (timer == 0) { Attack(); timer = coolDown; } } if (target == null) { ally_targeting al = (ally_targeting)GetComponent("ally_targeting"); al.targets = new System.Collections.Generic.List <UnityEngine.Transform>(); al.AddAllEnemy(); } }
void OnGUI() { GameObject go = GameObject.FindGameObjectWithTag("Player"); ally_targeting at = (ally_targeting)go.GetComponent("ally_targeting"); Enemy_AI ea = (Enemy_AI)me.GetComponent("Enemy_AI"); if (Vector3.Distance(me.transform.position, at.gameObject.transform.position) <= ea.maxDistance * 2) { if (at.targets.Count == 1) { if (me.transform == at.targets[0]) { healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth); healthBarPlace = 10; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar); } } if (at.targets.Count == 2) { if (me.transform == at.targets[0]) { healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth); healthBarPlace = 10; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar); } if (me.transform == at.targets[1]) { healthBarLength = (Screen.width / 3) * (curHealth / maxHealth); healthBarPlace = 70; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar); } } if (at.targets.Count == 3) { if (me.transform == at.targets[0]) { healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth); healthBarPlace = 10; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar); } if (me.transform == at.targets[1]) { healthBarLength = (Screen.width / 3) * (curHealth / maxHealth); healthBarPlace = 70; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar); } if (me.transform == at.targets[2]) { healthBarLength = (Screen.width / 4) * (curHealth / maxHealth); healthBarPlace = 120; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4) + 45, healthBarPlace + 20, healthBarLength - 55, 10), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4), healthBarPlace, Screen.width / 4, 30), horizontalHealthBar); } } if (at.targets.Count > 4) { if (me.transform == at.targets[0]) { healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth); healthBarPlace = 10; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2) + 90, healthBarPlace + 40, healthBarLength - 100, 20), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 2), healthBarPlace, Screen.width / 2, 60), horizontalHealthBar); } if (me.transform == at.targets[1]) { healthBarLength = (Screen.width / 3) * (curHealth / maxHealth); healthBarPlace = 70; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3) + 60, healthBarPlace + (40 - 15), healthBarLength - 65, 15), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 3), healthBarPlace, Screen.width / 3, 40), horizontalHealthBar); } if (me.transform == at.targets[2]) { healthBarLength = (Screen.width / 4) * (curHealth / maxHealth); healthBarPlace = 120; GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4) + 45, healthBarPlace + 20, healthBarLength - 55, 10), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - Screen.width / 4), healthBarPlace, Screen.width / 4, 30), horizontalHealthBar); } if (me.transform == at.targets[3]) { healthBarLength = Screen.height / 3; healthBarPlace = 155; GUI.DrawTexture(new Rect((Screen.width - (25 + 25 / 3) + 7), healthBarPlace + 25, 15 + 15 / 3 - 3, healthBarLength - 35), healthBarColor); GUI.DrawTexture(new Rect((Screen.width - (35 + 35 / 3)), healthBarPlace, 30 + 30 / 3, Screen.height / 3), verticalHeathBar); } } } }