// Use this for initialization void Start() { mAnim = mPlayer.GetComponent <Animator>(); //获取玩家及敌人脚本类 playerScript = mPlayer.GetComponent <PlayerMode>(); enemyScript = mEnemy.GetComponent <MonsterMode>(); }
// Method to be used by the view controller to pass in the data. public void setupData(int level, int rooms, TrapMode traps, MonsterMode monsters, DifficultyLevel difficulty, TreasureMode treasure) { // Setup the data with the variables passed in. this.level = level; numberOfRooms = rooms; trapMode = traps; monsterMode = monsters; this.difficulty = difficulty; treasureMode = treasure; }
void OnCollisionEnter(Collision collision) { if(collision.transform.name.Contains("Fireball")){ Debug.Log("Fireball Hit"); Instantiate(explode,collision.transform.position,collision.transform.rotation); monstermode = MonsterMode.dead; } else if(collision.transform.name.Contains("Sword")){ Debug.Log("Sword Hit"); Instantiate(bleeding,collision.transform.position,collision.transform.rotation); monstermode = MonsterMode.dead; } else if(collision.transform.name.Contains("ElectricWave")){ Debug.Log("ElectricWave Hit"); GetComponent<ParticleRenderer>().enabled = true; monstermode = MonsterMode.dead; } }
/// <summary> /// /// </summary> /// <returns></returns> private bool DetectPlayer() { // Check if the player is within detection range, and if so, attempt // detection. if (m_playerDistance < MaxDetectionDistance) { // Calculate the chance of detection based on the range to // the player. float playerDetectionChance = LinearTransform(m_playerDistance, 0, MaxDetectionDistance, MaxDetectionChance, 0); if (Random.value < playerDetectionChance) { // If we have detected the player, attempt to get a path. if (m_seeker.IsDone()) { Path path = m_seeker.StartPath(transform.position, Player.transform.position); if (!path.error) { // Reset pathfinding variables. m_lastPathfindingUpdate = 0f; m_currentPath = path; m_currentWaypoint = 0; // Change the change to skeleton state and update animation // variables. m_mode = MonsterMode.Hunting; m_animator.SetFloat("Speed", 1); return true; } } } } return false; }
protected void WaitUntil(float time) { waitingUntil = time; _mode = MonsterMode.Wait; }
private void UpdateRoar() { if (m_attackStart) { m_attackTime = 0; m_attackStart = false; } m_attackTime += Time.deltaTime; if (m_attackTime > 2.76) { m_attackTime = 0; m_attackStart = true; m_currentPath = null; m_currentWaypoint = -1; m_animator.SetBool("Roar", false); m_mode = MonsterMode.Idle; } }
private void UpdatePatrolling() { m_playerDetected = DetectPlayer(); if (m_playerDetected) return; // Test if we have just reached the end of the path. if (m_currentWaypoint >= m_currentPath.vectorPath.Count) { m_currentPath = null; m_currentWaypoint = -1; m_animator.SetFloat("Speed", 0); m_animator.SetBool("FacingOff", false); m_mode = MonsterMode.Idle; return; } Move(); }
private void UpdateIdle() { if (m_playerDetected) { WalkSpeed = 0; // If within striking range attack the player at random intervals. If // not, attempt to get a path to the player and resume hunting. if (m_playerDistance < 2.5) { Vector3 displacement = Player.transform.position - transform.position; float angle = Vector3.Angle(transform.forward, displacement); if (Random.value < 0.25f && Mathf.Abs(angle) < 10) { float r = Random.value; if (r < 0.33) { m_animator.SetBool("Attack1", true); m_mode = MonsterMode.Attack1; } else if (r < 0.66) { m_animator.SetBool("Attack2", true); m_mode = MonsterMode.Attack2; } else if (r < 82.5) { m_animator.SetBool("Attack3", true); m_mode = MonsterMode.Attack3; } else { m_animator.SetBool("Roar", true); m_mode = MonsterMode.Roar; } return; } // Reorientate the controller to face towards the player. Vector3 direction = Player.transform.position - transform.position; direction.Normalize(); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(direction), 3.5f * Time.deltaTime); } else { if (m_seeker.IsDone()) { Path path = m_seeker.StartPath(transform.position, Player.transform.position); if (!path.error) { // Reset pathfinding variables. m_lastPathfindingUpdate = 0f; m_currentPath = path; m_currentWaypoint = 0; // Change the change to skeleton state and update animation // variables. m_mode = MonsterMode.Hunting; m_animator.SetFloat("Speed", 1); } } } } else { m_playerDetected = DetectPlayer(); if (m_playerDetected) return; // Check if the controller should transition from idle to patrolling. if (Random.value < PatrolChance) { // Get a point within a radius of PatrolRadius units. Vector2 randomPoint = Random.insideUnitCircle * PatrolRadius; Vector3 end = transform.position; end.x += randomPoint.x; end.y = 0.5f; end.z += randomPoint.y; if (m_seeker.IsDone()) { Path path = m_seeker.StartPath(transform.position, end); if (!path.error) { m_lastPathfindingUpdate = 0f; m_currentPath = path; m_currentWaypoint = 0; m_mode = MonsterMode.Patrolling; m_animator.SetFloat("Speed", 0.5f); m_animator.SetBool("FacingOff", false); return; } } } } }
private void UpdateHunting() { WalkSpeed = 75; if (m_playerDistance < 2.0) { m_animator.SetFloat("Speed", 0); m_mode = MonsterMode.Idle; return; } // Check if we have reached the end of the current path. if (m_currentWaypoint >= m_currentPath.vectorPath.Count) { // If so, find a new path to the player. Path path = m_seeker.StartPath(transform.position, Player.transform.position); if (!path.error) { m_lastPathfindingUpdate = 0f; m_lastPlayerPos = Player.transform.position; m_currentPath = path; m_currentWaypoint = 0; } } // If the player has moved significantly since last pathfinding and more // than the designated pathfinding interval has passed... m_lastPathfindingUpdate += Time.deltaTime; if (m_lastPathfindingUpdate > HuntingPathfindingInterval) { // Re-path to the player and reset pathfinding variables. if (m_seeker.IsDone()) { Path path = m_seeker.StartPath(transform.position, Player.transform.position); if (!path.error) { m_lastPlayerPos = Player.transform.position; m_currentPath = path; m_currentWaypoint = 0; } m_lastPathfindingUpdate = 0f; } } Move(); }
void Update() { distance = Vector3.Distance(myTransform.position,target.position); if(monstermode==MonsterMode.idle){ if(distance<active_range){ audio.Play(); monstermode = MonsterMode.attack; } return; } else if(monstermode==MonsterMode.attack){ if(distance>active_range){ monstermode = MonsterMode.idle; } else if(distance>attack_range){ if(!animation.isPlaying){ animation.Play("attack"); } } else{ //attack Debug.Log("jackyattack"); if(jackywave_time<5f){ jackywave_time += Time.deltaTime; } else{ soundManager.PlayAudioClipNew(soundManager.jackyattack,soundManager.Volum_jackyattack); Instantiate(jackywave,wavePosition.position,wavePosition.rotation); jackywave_time = 0f; } } } else if(monstermode==MonsterMode.dead){ if(dead==false){ dead=true; //play dead animation -> IEmunator to destroy; soundManager.PlayAudioClipNew(soundManager.jackydead,soundManager.Volum_jackydead); MonsterDead(); } } }
void Update() { distance = Vector3.Distance(myTransform.position,target.position); if(monstermode==MonsterMode.idle){ if(distance<active_range){ monstermode = MonsterMode.attack; } return; } else if(monstermode==MonsterMode.attack){ if(distance>active_range){ monstermode = MonsterMode.idle; } else if(distance>attack_range){ if(!animation.isPlaying){ animation.Play("walk"); } if(!audio.isPlaying){ audio.Play(); } //Look at target myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(SetYZero(target.position) - SetYZero(myTransform.position)), rotationspeed*Time.deltaTime); //Move towards target Vector3 temp = new Vector3(myTransform.forward.x,0,myTransform.forward.z); myTransform.position += temp * movespeed * Time.deltaTime; } else{ //melee attack animation["attack"].speed = 0.8f; animation.Play("attack"); audio.Stop(); if(!soundManager.isPlayingAudioClip(soundManager.mickyattack)){ if(guiScript.HP>0 && guiScript.shielded==false){ guiScript.HP -= 10f; guiScript.recover_time = 0f; } soundManager.PlayAudioClip(soundManager.mickyattack,soundManager.Volum_mickyattack); } } } else if(monstermode==MonsterMode.dead){ if(dead==false){ dead=true; //play dead animation -> IEmunator to destroy; soundManager.PlayAudioClipNew(soundManager.mickydead,soundManager.Volum_mickydead); MonsterDead(); } } }