//do a renewed search for a target void updateTarget() { GameObject[] baddies = GameObject.FindGameObjectsWithTag(baddieTag); //just to make sure our shortest distance is set float shortestDistance = Mathf.Infinity; //once we find one GameObject nearestBaddie = null; foreach (GameObject baddie in baddies) { float distanceToBaddie = Vector3.Distance(transform.position, baddie.transform.position); //Check if there is one closer if (distanceToBaddie < shortestDistance) { //update distance and store nearest shortestDistance = distanceToBaddie; nearestBaddie = baddie; } } //found baddie in range if (nearestBaddie != null && shortestDistance <= range) { target = nearestBaddie.transform; targetBaddie = nearestBaddie.GetComponent <Baddie>(); } else { target = null; } }
void damage(Transform baddie) //entire transform { Baddie baddieScript = baddie.GetComponent <Baddie>(); if (baddieScript != null) { //hurt the enemy baddieScript.takeDamage(bulletDamage); } }
public void AttachBaddie(Baddie b) { attached.Add(b); b.transform.parent = transform; b.transform.position = b.transform.position; attachSound.Play(); RecomputeSize(); //TODO COME UP WITH REAL SCORING (Score based on pickups on number of baddies attacahed?) UpdateScore(); }
void OnPlayerHit(object sender, BaddieEventArgs args) { if (!knockedBack) { Baddie baddie = args.baddiePayload; this.health -= baddie.damage; _data.health = health; animator.SetBool("hit", true); knockedBack = true; cantMove = true; knockBackFrame = 0; knockDirection = (this.transform.position - baddie.gameObject.transform.position).normalized * knockBackSpeed * Time.deltaTime; hitNoise.Play(); baddie.Die(); } }
// Update is called once per frame void OnPlayerHit(object sender, BaddieEventArgs args) { Baddie baddie = args.baddiePayload; float damage = baddie.damage; if (!hit) { if (healthCurrent - damage > 0) { hit = true; iFrame = 0; } else { GameOver = true; button.gameObject.GetComponent <Button>().interactable = true; contButton.gameObject.GetComponent <Button>().interactable = true; StartCoroutine("delayGameOver"); } ChangeHeart(baddie.damage); } }
private void Start() { baddie = GetComponent <Baddie>(); target = Waypoints.waypoints[0]; }
// Update is called once per frame void Update() { Collider2D[] firsHit = new Collider2D[1]; col.OverlapCollider(new ContactFilter2D(), firsHit); if (firsHit[0] != null) { if (baddieProjectile) { if (firsHit[0].gameObject.tag.Equals("Player")) { // Object.Destroy(firsHit[0].gameObject); mainChar b = firsHit[0].GetComponent <mainChar>(); b.takeDamage(damage); Object.Destroy(gameObject); } if (!firsHit[0].gameObject.tag.Equals("Baddie")) { Object.Destroy(gameObject); } } else { if (firsHit[0].gameObject.tag.Equals("Baddie")) { // Object.Destroy(firsHit[0].gameObject); Baddie b = firsHit[0].GetComponent <Baddie>(); if (b.hp - damage < 0) { int newdamage = damage - b.hp; b.takeDamg(damage); damage = newdamage; } else { b.takeDamg(damage); hits = peirce; } hits++; } if (!firsHit[0].gameObject.tag.Equals("Player") && hits > peirce || firsHit[0].gameObject.tag.Equals("Wall")) { Object.Destroy(gameObject); } } } transform.Translate(new Vector3(Time.deltaTime * speed * 50, 0, 0)); if (!render.isVisible) { Object.Destroy(gameObject); } }
public void BaddieDestroyed(Baddie baddie) { baddies.Remove(baddie); }
public bool Attack(Vector2 position, float angle) { bool attacked = false; if (timeSinceLastAttack > attackSpeed * attackSpeedMod) { attacked = true; timeSinceLastAttack = 0; //Move to same place transform.position = position; if (angle >= -45 && angle < 45) { // Debug.Log("Right"); transform.position = new Vector3(transform.position.x + attackOffSet.x, transform.position.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 0); } if (angle >= 45 && angle < 135) { //Debug.Log("Up"); transform.position = new Vector3(transform.position.x, transform.position.y + attackOffSet.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 90); } if (angle >= 135 || angle < -135) { /// Debug.Log("Left"); transform.position = new Vector3(transform.position.x - attackOffSet.x, transform.position.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 180); } if (angle >= -135 && angle < -45) { // Debug.Log("Down"); transform.position = new Vector3(transform.position.x, transform.position.y - attackOffSet.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 270); } Collider2D[] results = new Collider2D[cleaveNumber]; col.OverlapCollider(new ContactFilter2D(), results); int hit = 0; for (int i = 0; i < results.Length; i++) { if (results[i] != null && !results[i].gameObject.tag.Equals("Player")) { hit++; if (results[i].gameObject.tag.Equals("Baddie")) { //Object.Destroy(results[i].gameObject); Baddie b = results[i].GetComponent <Baddie>(); b.takeDamg(attackDamage); } } } } return(attacked); }
void renderBaddie(Baddie b, int x, int y) { Sprite s = sd["swarmer"]; tiles[x, y].GetComponent <SpriteRenderer>().sprite = s; }
public static void InvokePlayerHit(Baddie baddie) { PlayerHit(null, new BaddieEventArgs { baddiePayload = baddie }); }