Refactored enemy: Bird & removed potential bug

This commit is contained in:
MarcUs7i 2024-10-09 11:24:07 +02:00
parent 39fc11cfe6
commit c1fa7a72b9
15 changed files with 118 additions and 125 deletions

View file

@ -1104,9 +1104,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
standardUI: []
secondUI: []
changeWhenEnabledUI: []
changeWhenDisabledUI: []
sceneFader: {fileID: 301995584}
changeOnlyWhenEnabledUI: []
changeOnlyWhenDisabledUI: []
--- !u!4 &263201670
Transform:
m_ObjectHideFlags: 0
@ -3704,7 +3703,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5e0d4b501440e334183393b36d054f36, type: 3}
m_Name:
m_EditorClassIdentifier:
animator: {fileID: 956474836}
--- !u!95 &956474836
Animator:
serializedVersion: 5
@ -15857,7 +15855,7 @@ GameObject:
- component: {fileID: 1904693563}
- component: {fileID: 1904693564}
m_Layer: 0
m_Name: 'Clouds Note: 15.841 space between'
m_Name: Clouds
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

View file

@ -8,13 +8,11 @@ public class MusicValue : MonoBehaviour
{
private Slider mainSlider;
// Start is called before the first frame update
void Awake()
{
mainSlider = GetComponent<Slider>();
}
// Update is called once per frame
void Update()
{
mainSlider.value = SoundBar.SoundVolume;

View file

@ -10,7 +10,7 @@ public class EnemyAI : MonoBehaviour
public float speed = 200f;
public float nextWaypointDistance = 3f;
public Transform enemyGFX;
private Transform enemyGFX;
Path path;
int currentWaypoint = 0;
@ -20,11 +20,11 @@ public class EnemyAI : MonoBehaviour
Seeker seeker;
Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
seeker = GetComponent<Seeker>();
rb = GetComponent<Rigidbody2D>();
enemyGFX = GetComponentInChildren<SpriteRenderer>().transform;
InvokeRepeating("UpdatePath", 0f, .5f);
}
@ -46,7 +46,6 @@ public class EnemyAI : MonoBehaviour
}
}
// Update is called once per frame
void FixedUpdate()
{
if (Pause.IsPause == false)

View file

@ -5,49 +5,47 @@ using Pathfinding;
public class BirdBoss : MonoBehaviour
{
public Animator animator;
public Transform target;
public float SlowSpeed = 100f;
public float NormalSpeed = 300f;
public float FastSpeed = 500f;
public float speed = 300f;
[Header("Speed & Range")]
public float defaultSpeed = 300f;
public float StartRange = 20f;
public float attackableRange = 10f;
[Header("Encourage")]
public float encourageSpeed = 700f;
public float encourageSec = 2.0f;
[Header("Pathfinding")]
public float nextWaypointDistance = 3f;
int currentWaypoint = 0;
[Header("Audio")]
public AudioSource BackgroundMusic;
public AudioSource audioSource;
bool IsPlay = false;
AudioSource audioSFX;
public Transform enemyGFX;
[Header("Health")]
public int health = 100;
public GameObject deathEffect;
Path path;
int currentWaypoint = 0;
bool start = false;
public float StartRange = 20f;
Animator animator;
Transform enemyGFX;
Seeker seeker;
Rigidbody2D rb;
//health
public int health = 100;
public GameObject deathEffect;
public static bool BirdDead = false;
bool StopHearting = false;
bool TimeStopHearting = false;
float encourageStart = 1f;
bool DamageAnim = false;
float distance;
public float range = 10f;
bool Stop = false;
bool StopHurting = false;
bool isInStage2 = false;
bool transitioningToStage2 = false;
void Start()
{
seeker = GetComponent<Seeker>();
rb = GetComponent<Rigidbody2D>();
animator = GetComponentInChildren<Animator>();
enemyGFX = GetComponentInChildren<SpriteRenderer>().transform;
audioSFX = GetComponent<AudioSource>();
InvokeRepeating("UpdatePath", 0f, .5f);
}
@ -71,7 +69,18 @@ public class BirdBoss : MonoBehaviour
void FixedUpdate()
{
if (Pause.IsPause == false && Stop == false && start == true)
if(Pause.IsPause)
{
return;
}
float distance = Vector2.Distance(transform.position, target.position);
if (health <= 25 && !isInStage2)
{
StartCoroutine(Encourage());
}
if (!transitioningToStage2 && distance < StartRange)
{
if (path == null)
{
@ -83,11 +92,11 @@ public class BirdBoss : MonoBehaviour
}
Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] -rb.position).normalized;
Vector2 force = direction * speed * Time.deltaTime;
Vector2 force = direction * defaultSpeed * Time.deltaTime;
rb.AddForce(force);
float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);
distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);
if (distance < nextWaypointDistance)
{
@ -109,7 +118,8 @@ public class BirdBoss : MonoBehaviour
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.tag == "Bullet" && distance < range && StopHearting == false && TimeStopHearting == false)
float distance = Vector2.Distance(transform.position, target.position);
if (collider.gameObject.tag == "Bullet" && distance < attackableRange && !StopHurting)
{
TakeDamage(10);
}
@ -126,7 +136,7 @@ public class BirdBoss : MonoBehaviour
// Health
void TakeDamage(int damage)
{
if (MainMenu.ExitLevel == false)
if (!MainMenu.ExitLevel)
{
health -= damage;
@ -135,48 +145,13 @@ public class BirdBoss : MonoBehaviour
if (health <= 0)
{
Die();
// Die
Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
}
void Die ()
{
BirdDead = true;
Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
// Health End
void Update()
{
if (Pause.IsPause == false)
{
if (health <= 25 && encourageStart == 1f)
{
StartCoroutine(Encourage());
}
if (start == false)
{
float distancce = Vector2.Distance(transform.position, target.position);
if (distancce < StartRange)
{
//Debug.Log("started");
start = true;
}
}
if (IsPlay == true)
{
StartCoroutine(Music());
IsPlay = false;
}
}
}
IEnumerator Attack()
{
animator.SetBool("Attack", true);
@ -187,46 +162,42 @@ public class BirdBoss : MonoBehaviour
IEnumerator DamageAnimation()
{
if (health <= 60 && encourageStart == 1f)
{
DamageAnim = true;
}
if (DamageAnim == false)
{
animator.SetBool("Damage", true);
yield return new WaitForSeconds(2.0f);
animator.SetBool("Damage", false);
}
animator.SetBool("Damage", true);
yield return new WaitForSeconds(2.0f);
animator.SetBool("Damage", false);
}
IEnumerator Encourage()
{
StopHearting = true;
encourageStart++;
StopHurting = true;
isInStage2 = true;
animator.SetBool("Encourage", true);
Stop = true;
IsPlay = true;
NormalSpeed = FastSpeed;
speed = encourageSpeed;
transitioningToStage2 = true;
StartCoroutine(Music());
defaultSpeed = encourageSpeed;
yield return new WaitForSeconds(encourageSec);
//animator.SetBool("Encourage", false);
Stop = false;
StopHearting = false;
DamageAnim = false;
transitioningToStage2 = false;
StopHurting = false;
}
IEnumerator BulletAttacked()
{
TimeStopHearting = true;
StopHurting = true;
yield return new WaitForSeconds(2.0f);
TimeStopHearting = false;
StopHurting = false;
}
IEnumerator Music()
{
float oldVolume = BackgroundMusic.volume;
BackgroundMusic.volume = 0.25f;
audioSource.Play();
audioSFX.Play();
yield return new WaitForSeconds(3.0f);
BackgroundMusic.volume = 0.75f;
BackgroundMusic.volume = oldVolume;
}
}

View file

@ -4,11 +4,20 @@ using UnityEngine;
public class BirdBossAutomaticDoor : MonoBehaviour
{
public Transform door;
Transform door;
BirdBoss birdBoss;
public float speed = 5f;
bool isAllowedToOpen = true;
void Start()
{
door = GetComponent<Transform>();
birdBoss = FindObjectOfType<BirdBoss>().GetComponent<BirdBoss>();
}
void Update()
{
if (BirdBoss.BirdDead == true)
if (birdBoss.health <= 0 && isAllowedToOpen)
{
transform.position += Vector3.up * speed * Time.deltaTime;
StartCoroutine(StopDoor());
@ -18,6 +27,6 @@ public class BirdBossAutomaticDoor : MonoBehaviour
IEnumerator StopDoor()
{
yield return new WaitForSeconds(2.0f);
BirdBoss.BirdDead = false;
isAllowedToOpen = false;
}
}

View file

@ -2,26 +2,26 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class BirdBossHealthBar : MonoBehaviour
{
public BirdBoss birdBoss;
public Animator animator;
int NewHealth = 100;
BirdBoss birdBoss;
Animator animator;
void Start()
{
birdBoss = GetComponentInParent<BirdBoss>();
animator = GetComponent<Animator>();
animator.SetBool("100", true);
}
void Update()
{
NewHealth = (birdBoss.health * 100) / 200;
int[] health = { 100, 75, 50, 25 };
for (int i = 0; i < 4; i++)
{
animator.SetBool(health[i].ToString(), health[i] == NewHealth);
animator.SetBool(health[i].ToString(), birdBoss.health >= health[i]);
}
}
}

View file

@ -6,7 +6,7 @@ AnimationClip:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 100%Leben
m_Name: 100%Live
serializedVersion: 6
m_Legacy: 0
m_Compressed: 0

View file

@ -6,7 +6,7 @@ AnimationClip:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 25%Leben
m_Name: 25%Live
serializedVersion: 6
m_Legacy: 0
m_Compressed: 0

View file

@ -6,7 +6,7 @@ AnimationClip:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 50%Leben
m_Name: 50%Live
serializedVersion: 6
m_Legacy: 0
m_Compressed: 0

View file

@ -6,7 +6,7 @@ AnimationClip:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 75%Leben
m_Name: 75%Live
serializedVersion: 6
m_Legacy: 0
m_Compressed: 0

View file

@ -8,6 +8,9 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: 100
m_EventTreshold: 0
- m_ConditionMode: 1
m_ConditionEvent: 75
m_EventTreshold: 0
@ -74,25 +77,25 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: 75
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: 50
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: 25
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@ -113,7 +116,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 100%Leben
m_Name: 100%Live
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
@ -139,7 +142,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 75%Leben
m_Name: 75%Live
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
@ -166,6 +169,12 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: 100
m_EventTreshold: 0
- m_ConditionMode: 2
m_ConditionEvent: 75
m_EventTreshold: 0
- m_ConditionMode: 1
m_ConditionEvent: 50
m_EventTreshold: 0
@ -191,6 +200,15 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: 100
m_EventTreshold: 0
- m_ConditionMode: 2
m_ConditionEvent: 75
m_EventTreshold: 0
- m_ConditionMode: 2
m_ConditionEvent: 50
m_EventTreshold: 0
- m_ConditionMode: 1
m_ConditionEvent: 25
m_EventTreshold: 0
@ -215,7 +233,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 25%Leben
m_Name: 25%Live
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []
@ -241,7 +259,7 @@ AnimatorState:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: 50%Leben
m_Name: 50%Live
m_Speed: 1
m_CycleOffset: 0
m_Transitions: []