// ATTACK public void attack(AbstractEntity enemy, Vector3 enemyPos){ if(this.isAlive() && enemy.isAlive()){ this.lookAt (enemyPos); if (timeForNextAction<=0){ if (animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", false); if (animator.GetBool("walk_enabled")) animator.SetBool ("walk_enabled", false); if (!animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", true); PNJAudio.PlayOgreHit(); enemy.onAttackReceived (DMG); timeForNextAction = timecost_perAction; } }else if (animator.GetBool("attack_enabled")){ animator.SetBool("attack_enabled",false); } }
void LateUpdate() { RaycastHit hit; GameObject player = GameObject.FindWithTag("Player"); if (Camera.main != null && player != null) { AbstractEntity entity = player.GetComponent <AbstractEntity>(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (entity.isAlive() && Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << layer)) { Transform target = hit.transform; //Debug.Log("ray.origin: " + ray.origin); //Debug.Log("ray.direction: " + ray.direction); if (target == transform) { overrideShader(); } else { restoreShader(); } } else { restoreShader(); } } else { restoreShader(); } }
// ATTACK public void attack(AbstractEntity enemy, Vector3 enemyPos){ this.lookAt(enemyPos); if(this.isAlive() && enemy.isAlive()){ if (timeForNextAction<=0){ float randomNumber = Random.Range(0f,100f); if (randomNumber<25){ if (animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", false); if (!animator.GetBool("critical")) animator.SetBool ("critical", true); PNJAudio.PlayCriticalAttack(); // PlayAttackOK enemy.onAttackReceived (4*DMG); timeForNextAction = timecost_perAction; }else{ if (animator.GetBool("critical")) animator.SetBool ("critical", false); if (!animator.GetBool("attack_enabled")) animator.SetBool ("attack_enabled", true); PNJAudio.PlayAttackOK(); // PlayCriticalAttack enemy.onAttackReceived (DMG); timeForNextAction = timecost_perAction; } } }else if (animator.GetBool("attack_enabled")){ animator.SetBool("attack_enabled",false); }else if (animator.GetBool("critical")){ animator.SetBool("critical",false); } }
void phase_control() { if (playerEntity.isAlive()) { GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); GameObject enemy; AbstractEntity enemyEntity; if (phase == INITIAL_PHASE) { bool spidersCleared = true; for (int i = 0; i < enemies.Length; i++) { enemy = enemies[i]; enemyEntity = enemy.GetComponent <AbstractEntity>(); if (enemyEntity != null) { if (!enemyEntity.isAlive()) { //enemy.GetComponent<SpiderState>().destroyWithDelay(1f); } else { spidersCleared = false; } } } if (spidersCleared) { phase = TROLL_FIGHT; for (int i = 0; i < enemies.Length; i++) { enemy = enemies[i]; enemyEntity = enemy.GetComponent <AbstractEntity>(); if (enemyEntity != null) { if (!enemyEntity.isAlive()) { enemy.GetComponent <SpiderState>().destroyObject(); } } } Invoke("spawnSpiders", 2f); Invoke("open_door", 2f); if (trollSpawner != null) { Object prefab = Resources.Load("troll", typeof(GameObject)); GameObject clone = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; clone.transform.position = trollSpawner.position; clone.GetComponent <NavMeshAgent> ().enabled = true; clone.GetComponent <TrollAI> ().enabled = true; } } } else if (phase == TROLL_FIGHT) { SpiderState spiderstate; TrollState trollstate; for (int i = 0; i < enemies.Length && phase == TROLL_FIGHT; i++) { enemy = enemies[i]; enemyEntity = enemy.GetComponent <AbstractEntity>(); if (enemyEntity != null) { if (!enemyEntity.isAlive()) { spiderstate = enemy.GetComponent <SpiderState>(); trollstate = enemy.GetComponent <TrollState>(); if (spiderstate != null) { spiderstate.destroyWithDelay(1.5f); Invoke("spawnSpiders", 2f); } if (trollstate != null) { if (!trollstate.isAlive()) { phase = GAME_COMPLETE; GameObject player = GameObject.FindGameObjectWithTag("Player"); Animator a = player.GetComponent <Animator>(); a.SetBool("fanfare", true); Invoke("show_win_message", 3); } } } } } } else { for (int i = 0; i < enemies.Length; i++) { enemy = enemies[i]; SpiderState spiderstate = enemy.GetComponent <SpiderState>(); if (spiderstate != null) { spiderstate.substractHealth(spiderstate.getHP()); spiderstate.destroyWithDelay(1f); } } } } else if (phase != GAME_OVER) { phase = GAME_OVER; } }