//Awake is always called before any Start functions void Awake() { //Check if instance already exists if (instance == null) { //if not, set instance to this instance = this; } //If instance already exists and it's not this: else if (instance != this) { //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager. Destroy(gameObject); } //Sets this to not be destroyed when reloading scene DontDestroyOnLoad(gameObject); levelText = GameObject.Find("LevelText").GetComponent <Text>(); levelImage = GameObject.Find("LevelImage"); player = GameObject.Find("LightBandit").GetComponent <Bandit>(); //Assign enemies to a new List of Enemy objects. enemies = new List <EnemyBuilder>(); if (playerFoodPoints == null) { playerFoodPoints = 500; } //Get a component reference to the attached BoardManager script mapGenerator = GetComponent <MapGenerator>(); //Call the InitGame function to initialize the first level //Debug.Log("Awake Init"); InitGame(); }
void Update() { player = GameObject.FindWithTag("Player").GetComponent <Bandit>(); target = GameObject.FindGameObjectWithTag("Player").transform.position; swordPosition = transform.position; showDam = true; bool isDamageIncrease = damage >= player.damage; string text; if (isDamageIncrease) { text = "+" + (damage - player.damage); } else { text = "-" + (player.damage - damage); } wText.SetText(text, showDam, isDamageIncrease); if (Input.GetKeyDown(KeyCode.E)) { if (Mathf.Pow(target.x - swordPosition.x, 2) + Mathf.Pow(target.y - swordPosition.y, 2) <= 2) { player.damage = damage; StartCoroutine(ShowWeaponChange(damage)); player.weaponName = weaponName; gameObject.SetActive(false); } } }
protected override void OnCantMove <T> (T component) { Bandit hitPlayer = component as Bandit; animator.SetTrigger("enemyAttack"); if (hitPlayer) { GameObject.FindWithTag("Player").GetComponent <Bandit>().DecrementHealthFromPlayer(); } hitPlayer.DecrementHealthFromPlayer(); SoundManager.instance.RandomizeSfx(attackSound1, attackSound2); }
protected override void Start() { CaveGameManager.instance.AddEnemyToList(this); animator = GetComponent <Animator> (); target = GameObject.FindGameObjectWithTag("Player").transform; enemyPosition = transform.position; isAttackingPlayer = false; if (CaveGameManager.instance.GetLevel() <= 1) { hp = Random.Range(10, 50); multiplier = 1; } else if (CaveGameManager.instance.GetLevel() <= 5) { // 0-9:no reward, 10-19:fruit, 20-29:drink, 30-39: veg, 40-49: meat enemyHealthChange = GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().GetHealthChange(CaveGameManager.instance.GetLevel()); hp = Random.Range(10, 50) + enemyHealthChange; multiplier = 1; } else if (CaveGameManager.instance.GetLevel() > 5 && CaveGameManager.instance.GetLevel() <= 10) { enemyHealthChange = GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().GetHealthChange(CaveGameManager.instance.GetLevel()); hp = Random.Range(100, 500) + enemyHealthChange; multiplier = 10; } else if (CaveGameManager.instance.GetLevel() > 10 && CaveGameManager.instance.GetLevel() <= 15) { enemyHealthChange = GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().GetHealthChange(CaveGameManager.instance.GetLevel()); hp = Random.Range(500, 1000) + enemyHealthChange; multiplier = 20; } else if (CaveGameManager.instance.GetLevel() > 15 && CaveGameManager.instance.GetLevel() <= 20) { enemyHealthChange = GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().GetHealthChange(CaveGameManager.instance.GetLevel()); hp = Random.Range(1000, 5000) + enemyHealthChange; multiplier = 100; } else { enemyHealthChange = GameObject.FindWithTag("GameManager").GetComponent <AIEnemyHealth>().GetHealthChange(CaveGameManager.instance.GetLevel()); hp = Random.Range(5000, 20000) + enemyHealthChange; multiplier = 400; } originalHp = hp; healthBar.SetHealth(hp, originalHp); player = GameObject.FindWithTag("Player").GetComponent <Bandit>(); itemSpawn = GameObject.FindWithTag("GameManager").GetComponent <ItemSpawn>(); base.Start(); }
public void GetStats(bool toughEnemy) { if (CaveGameManager.instance.GetLevel() > 1) { damageChange = GameObject.FindWithTag("GameManager").GetComponent <AIPlayerDamage>().GetDamageChange(CaveGameManager.instance.GetLevel()); } else { damageChange = 0; } player = GameObject.FindWithTag("Player").GetComponent <Bandit>(); damage = handle.damage + hilt.damage + blade.damage + damageChange; knockback = handle.knockback + hilt.knockback + blade.knockback; speed = handle.speed + hilt.speed + blade.speed; durability = handle.durability + hilt.durability + blade.durability; maxDurability = durability; if (toughEnemy && player.damage >= damage) { if (CaveGameManager.instance.GetLevel() <= 5) { damage = player.damage + 1; } else if (CaveGameManager.instance.GetLevel() > 5 && CaveGameManager.instance.GetLevel() <= 10) { damage = player.damage + 5; } else if (CaveGameManager.instance.GetLevel() > 10 && CaveGameManager.instance.GetLevel() <= 15) { damage = player.damage + 10; } else if (CaveGameManager.instance.GetLevel() > 15 && CaveGameManager.instance.GetLevel() <= 20) { damage = player.damage + 50; } else { damage = player.damage + 100; } } }
// Update is called once per frame void Update() { player = GameObject.FindWithTag("Player").GetComponent <Bandit>(); enemyPosition = transform.position; if (target.position.x > enemyPosition.x) { transform.localScale = new Vector3(0.8f, 0.8f, 1.0f); } else { transform.localScale = new Vector3(-0.8f, 0.8f, 1.0f); } if (Mathf.Pow(target.position.x - enemyPosition.x, 2) + Mathf.Pow(target.position.y - enemyPosition.y, 2) <= 1) { if (!isAttackingPlayer && !player.playerAttacking && !CaveGameManager.instance.playersTurn) { isAttackingPlayer = true; StartCoroutine(DamagePlayer()); } } if (player.playerAttacking == true) { if (Mathf.Pow(target.position.x - enemyPosition.x, 2) + Mathf.Pow(target.position.y - enemyPosition.y, 2) <= 1) { if (target.position.x - enemyPosition.x > 0 && player.facingLeft) { player.playerAttacking = false; StartCoroutine(DamageEnemy(player.damage)); } else if (target.position.x - enemyPosition.x < 0 && player.facingRight) { player.playerAttacking = false; StartCoroutine(DamageEnemy(player.damage)); } } } }
void Update() { player = GameObject.FindWithTag("Player").GetComponent <Bandit>(); target = GameObject.FindGameObjectWithTag("Player").transform.position; wallPosition = transform.position; if (player.playerAttacking == true) { if (Mathf.Pow(target.x - wallPosition.x, 2) + Mathf.Pow(target.y - wallPosition.y, 2) <= 2) { if (target.x - wallPosition.x > 0 && player.facingLeft) { player.playerAttacking = false; StartCoroutine(DamageWall(player.damage)); } else if (target.x - wallPosition.x < 0 && player.facingRight) { player.playerAttacking = false; StartCoroutine(DamageWall(player.damage)); } } } }
void Awake() { player = GameObject.Find("LightBandit").GetComponent <Bandit>(); }