mirror of
https://github.com/Kizuren/ShantiManti.git
synced 2025-12-21 21:16:04 +01:00
Refactored "Boss" scripts
This commit is contained in:
parent
744d57e236
commit
c9b1ba1c90
12 changed files with 386 additions and 309 deletions
|
|
@ -196,12 +196,12 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Priority:
|
||||
Enabled: 0
|
||||
m_Value: 0
|
||||
Enabled: 1
|
||||
m_Value: 10
|
||||
OutputChannel: 1
|
||||
StandbyUpdate: 2
|
||||
m_StreamingVersion: 20170927
|
||||
m_LegacyPriority: 10
|
||||
m_StreamingVersion: 20241001
|
||||
m_LegacyPriority: 0
|
||||
Target:
|
||||
TrackingTarget: {fileID: 820667352}
|
||||
LookAtTarget: {fileID: 0}
|
||||
|
|
@ -4826,10 +4826,6 @@ PrefabInstance:
|
|||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 733867154069418468, guid: 7dcd7bf6b73974b41a58ae3191280b93, type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 15
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 733867154069418468, guid: 7dcd7bf6b73974b41a58ae3191280b93, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 13.65
|
||||
|
|
|
|||
|
|
@ -196,12 +196,12 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Priority:
|
||||
Enabled: 0
|
||||
m_Value: 0
|
||||
Enabled: 1
|
||||
m_Value: 10
|
||||
OutputChannel: 1
|
||||
StandbyUpdate: 2
|
||||
m_StreamingVersion: 20170927
|
||||
m_LegacyPriority: 10
|
||||
m_StreamingVersion: 20241001
|
||||
m_LegacyPriority: 0
|
||||
Target:
|
||||
TrackingTarget: {fileID: 820667352}
|
||||
LookAtTarget: {fileID: 0}
|
||||
|
|
@ -3527,10 +3527,6 @@ PrefabInstance:
|
|||
propertyPath: m_Name
|
||||
value: BirdBoss
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2419347479429335679, guid: 8349dd52104ed2149a34ee68d7706e88, type: 3}
|
||||
propertyPath: m_RootOrder
|
||||
value: 15
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2419347479429335679, guid: 8349dd52104ed2149a34ee68d7706e88, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 24.01
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2419347479429335664}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 3.01, y: 2.34, z: 0}
|
||||
m_LocalScale: {x: 5, y: 5, z: 1}
|
||||
|
|
@ -36,7 +37,6 @@ Transform:
|
|||
- {fileID: 2419347479595545483}
|
||||
- {fileID: 6542085091776195959}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &2419347479429335677
|
||||
MonoBehaviour:
|
||||
|
|
@ -74,17 +74,37 @@ CircleCollider2D:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2419347479429335664}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: -0.0050656796, y: -0.012603248}
|
||||
serializedVersion: 2
|
||||
m_Radius: 0.11864553
|
||||
--- !u!50 &2340437267454439355
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -95,10 +115,16 @@ Rigidbody2D:
|
|||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 1.5
|
||||
m_AngularDrag: 0.05
|
||||
m_LinearDamping: 1.5
|
||||
m_AngularDamping: 0.05
|
||||
m_GravityScale: 0
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
|
|
@ -115,22 +141,16 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: c4aadb674b65f38428252e59975ee56a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
animator: {fileID: 2419347479595545482}
|
||||
target: {fileID: 0}
|
||||
SlowSpeed: 300
|
||||
NormalSpeed: 500
|
||||
FastSpeed: 700
|
||||
speed: 500
|
||||
encourageSpeed: 900
|
||||
encourageSec: 2
|
||||
defaultSpeed: 700
|
||||
StartRange: 20
|
||||
attackableRange: 10
|
||||
stage2Speed: 1400
|
||||
stage2AnimSec: 2
|
||||
nextWaypointDistance: 3
|
||||
BackgroundMusic: {fileID: 0}
|
||||
audioSource: {fileID: 1943202871}
|
||||
enemyGFX: {fileID: 2419347479595545483}
|
||||
StartRange: 20
|
||||
health: 100
|
||||
deathEffect: {fileID: 1755349173569476, guid: 3c45864be6a059a4a82a25e285298338, type: 3}
|
||||
range: 10
|
||||
--- !u!82 &1943202871
|
||||
AudioSource:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -142,6 +162,7 @@ AudioSource:
|
|||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: 66550d8a4f408fe419ebd6f376de6320, type: 3}
|
||||
m_Resource: {fileID: 8300000, guid: 66550d8a4f408fe419ebd6f376de6320, type: 3}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 1
|
||||
m_Pitch: 1
|
||||
|
|
@ -252,13 +273,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2419347479595545484}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2419347479429335679}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &2419347479595545481
|
||||
SpriteRenderer:
|
||||
|
|
@ -277,6 +298,9 @@ SpriteRenderer:
|
|||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
|
|
@ -314,7 +338,7 @@ SpriteRenderer:
|
|||
m_SpriteSortPoint: 0
|
||||
--- !u!95 &2419347479595545482
|
||||
Animator:
|
||||
serializedVersion: 4
|
||||
serializedVersion: 7
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -328,10 +352,12 @@ Animator:
|
|||
m_ApplyRootMotion: 0
|
||||
m_LinearVelocityBlending: 0
|
||||
m_StabilizeFeet: 0
|
||||
m_AnimatePhysics: 0
|
||||
m_WarningMessage:
|
||||
m_HasTransformHierarchy: 1
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
m_KeepAnimatorControllerStateOnDisable: 0
|
||||
m_KeepAnimatorStateOnDisable: 0
|
||||
m_WriteDefaultValuesOnDisable: 0
|
||||
--- !u!1 &6545398039632125933
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -358,13 +384,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6545398039632125933}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.361, z: 0}
|
||||
m_LocalScale: {x: 0.3, y: 0.17999999, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2419347479429335679}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &3815704246711606095
|
||||
SpriteRenderer:
|
||||
|
|
@ -383,6 +409,9 @@ SpriteRenderer:
|
|||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
|
|
@ -420,7 +449,7 @@ SpriteRenderer:
|
|||
m_SpriteSortPoint: 0
|
||||
--- !u!95 &5390178891040183903
|
||||
Animator:
|
||||
serializedVersion: 4
|
||||
serializedVersion: 7
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -434,10 +463,12 @@ Animator:
|
|||
m_ApplyRootMotion: 0
|
||||
m_LinearVelocityBlending: 0
|
||||
m_StabilizeFeet: 0
|
||||
m_AnimatePhysics: 0
|
||||
m_WarningMessage:
|
||||
m_HasTransformHierarchy: 1
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
m_KeepAnimatorControllerStateOnDisable: 0
|
||||
m_KeepAnimatorStateOnDisable: 0
|
||||
m_WriteDefaultValuesOnDisable: 0
|
||||
--- !u!114 &1017024877471322742
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -450,5 +481,3 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 13873c5fc244c8b48bd951589b7003d7, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
birdBoss: {fileID: 6793561339759360108}
|
||||
animator: {fileID: 5390178891040183903}
|
||||
|
|
|
|||
|
|
@ -8,194 +8,205 @@ public class BirdBoss : MonoBehaviour
|
|||
public Transform target;
|
||||
|
||||
[Header("Speed & Range")]
|
||||
public float defaultSpeed = 300f;
|
||||
public float defaultSpeed = 700f;
|
||||
public float StartRange = 20f;
|
||||
public float attackableRange = 10f;
|
||||
|
||||
[Header("stage2")]
|
||||
public float stage2Speed = 700f;
|
||||
public float stage2Speed = 1400f;
|
||||
public float stage2AnimSec = 2.0f;
|
||||
|
||||
[Header("Pathfinding")]
|
||||
public float nextWaypointDistance = 3f;
|
||||
int currentWaypoint = 0;
|
||||
private int _currentWaypoint;
|
||||
|
||||
[Header("Audio")]
|
||||
public AudioSource BackgroundMusic;
|
||||
AudioSource audioSFX;
|
||||
private AudioSource _audioSfx;
|
||||
|
||||
[Header("Health")]
|
||||
public int health = 100;
|
||||
public GameObject deathEffect;
|
||||
|
||||
[Header("Animation IDs")]
|
||||
private static readonly int AttackAnimationID = Animator.StringToHash("Attack");
|
||||
private static readonly int DamageAnimationID = Animator.StringToHash("Damage");
|
||||
private static readonly int EnterStage2AnimationID = Animator.StringToHash("EnterStage2");
|
||||
|
||||
Path path;
|
||||
Animator animator;
|
||||
Transform enemyGFX;
|
||||
Seeker seeker;
|
||||
Rigidbody2D rb;
|
||||
private Path _path;
|
||||
private Animator _animator;
|
||||
private Transform _enemyGfx;
|
||||
private Seeker _seeker;
|
||||
private Rigidbody2D _rb;
|
||||
|
||||
bool StopHurting = false;
|
||||
bool isInStage2 = false;
|
||||
bool transitioningToStage2 = false;
|
||||
private bool _startGoing;
|
||||
private bool _stopHurting;
|
||||
private bool _isInStage2;
|
||||
private bool _transitioningToStage2;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
seeker = GetComponent<Seeker>();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
enemyGFX = GetComponentInChildren<SpriteRenderer>().transform;
|
||||
_seeker = GetComponent<Seeker>();
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
_animator = GetComponentInChildren<Animator>();
|
||||
_enemyGfx = GetComponentInChildren<SpriteRenderer>().transform;
|
||||
|
||||
audioSFX = GetComponent<AudioSource>();
|
||||
_audioSfx = GetComponent<AudioSource>();
|
||||
_startGoing = false;
|
||||
|
||||
InvokeRepeating("UpdatePath", 0f, .5f);
|
||||
InvokeRepeating(nameof(UpdatePath), 0f, .5f);
|
||||
}
|
||||
|
||||
void UpdatePath()
|
||||
private void UpdatePath()
|
||||
{
|
||||
if (seeker.IsDone())
|
||||
if (_seeker.IsDone())
|
||||
{
|
||||
seeker.StartPath(rb.position, target.position, OnPathComplete);
|
||||
_seeker.StartPath(_rb.position, target.position, OnPathComplete);
|
||||
}
|
||||
}
|
||||
|
||||
void OnPathComplete (Path p)
|
||||
private void OnPathComplete (Path p)
|
||||
{
|
||||
if (!p.error)
|
||||
if (p.error)
|
||||
{
|
||||
path = p;
|
||||
currentWaypoint = 0;
|
||||
return;
|
||||
}
|
||||
_path = p;
|
||||
_currentWaypoint = 0;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(Pause.IsPause)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float distance = Vector2.Distance(transform.position, target.position);
|
||||
|
||||
var distance = Vector2.Distance(transform.position, target.position);
|
||||
|
||||
if (health <= 25 && !isInStage2)
|
||||
if (distance < StartRange && !_startGoing)
|
||||
{
|
||||
_startGoing = true;
|
||||
}
|
||||
|
||||
if (health <= 25 && !_isInStage2)
|
||||
{
|
||||
StartCoroutine(GetToStage2());
|
||||
}
|
||||
}
|
||||
|
||||
if (!transitioningToStage2 && distance < StartRange)
|
||||
if (!_transitioningToStage2 && _startGoing)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (currentWaypoint >= path.vectorPath.Count)
|
||||
if (_path == null || _currentWaypoint >= _path.vectorPath.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] -rb.position).normalized;
|
||||
Vector2 force = direction * defaultSpeed * Time.deltaTime;
|
||||
Vector2 direction = ((Vector2)_path.vectorPath[_currentWaypoint] -_rb.position).normalized;
|
||||
Vector2 force = direction * (defaultSpeed * Time.deltaTime);
|
||||
|
||||
rb.AddForce(force);
|
||||
_rb.AddForce(force);
|
||||
|
||||
distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);
|
||||
distance = Vector2.Distance(_rb.position, _path.vectorPath[_currentWaypoint]);
|
||||
|
||||
if (distance < nextWaypointDistance)
|
||||
{
|
||||
currentWaypoint++;
|
||||
_currentWaypoint++;
|
||||
}
|
||||
|
||||
//You can make look it differently, if you delete 'rb.velocity' and add 'force' instead.
|
||||
if (rb.linearVelocity.x >= 0.01f)
|
||||
// Flip enemy sprite
|
||||
if (_rb.linearVelocity.x >= 0.01f)
|
||||
{
|
||||
enemyGFX.transform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
_enemyGfx.transform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
}
|
||||
else if (rb.linearVelocity.x <= -0.01f)
|
||||
else if (_rb.linearVelocity.x <= -0.01f)
|
||||
{
|
||||
enemyGFX.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
_enemyGfx.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collider)
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
float distance = Vector2.Distance(transform.position, target.position);
|
||||
if (collider.gameObject.tag == "Bullet" && distance < attackableRange && !StopHurting)
|
||||
var distance = Vector2.Distance(transform.position, target.position);
|
||||
if (collider.gameObject.CompareTag("Bullet") && distance < attackableRange && !_stopHurting)
|
||||
{
|
||||
TakeDamage(10);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
StartCoroutine(Attack());
|
||||
}
|
||||
}
|
||||
|
||||
// Health
|
||||
void TakeDamage(int damage)
|
||||
{
|
||||
if (!MainMenu.ExitLevel)
|
||||
{
|
||||
health -= damage;
|
||||
|
||||
StartCoroutine(DamageAnimation());
|
||||
StartCoroutine(BulletAttacked());
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
// Die
|
||||
Instantiate(deathEffect, transform.position, Quaternion.identity);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Attack()
|
||||
private void TakeDamage(int damage)
|
||||
{
|
||||
animator.SetBool("Attack", true);
|
||||
if (MainMenu.ExitLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
health -= damage;
|
||||
|
||||
StartCoroutine(AnimateDamage());
|
||||
StartCoroutine(BulletAttacked());
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
// Die
|
||||
Instantiate(deathEffect, transform.position, Quaternion.identity);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Attack()
|
||||
{
|
||||
_animator.SetBool(AttackAnimationID, true);
|
||||
Enemy.TookDamage = true;
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
animator.SetBool("Attack", false);
|
||||
_animator.SetBool(AttackAnimationID, false);
|
||||
}
|
||||
|
||||
IEnumerator DamageAnimation()
|
||||
private IEnumerator AnimateDamage()
|
||||
{
|
||||
animator.SetBool("Damage", true);
|
||||
_animator.SetBool(DamageAnimationID, true);
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
animator.SetBool("Damage", false);
|
||||
_animator.SetBool(DamageAnimationID, false);
|
||||
}
|
||||
|
||||
IEnumerator GetToStage2()
|
||||
private IEnumerator GetToStage2()
|
||||
{
|
||||
StopHurting = true;
|
||||
isInStage2 = true;
|
||||
_stopHurting = true;
|
||||
_isInStage2 = true;
|
||||
|
||||
animator.SetBool("EnterStage2", true);
|
||||
transitioningToStage2 = true;
|
||||
StartCoroutine(Music());
|
||||
_animator.SetBool(EnterStage2AnimationID, true);
|
||||
_transitioningToStage2 = true;
|
||||
StartCoroutine(PlaySfx());
|
||||
|
||||
defaultSpeed = stage2Speed;
|
||||
yield return new WaitForSeconds(stage2AnimSec);
|
||||
|
||||
transitioningToStage2 = false;
|
||||
StopHurting = false;
|
||||
_transitioningToStage2 = false;
|
||||
_stopHurting = false;
|
||||
}
|
||||
|
||||
IEnumerator BulletAttacked()
|
||||
private IEnumerator BulletAttacked()
|
||||
{
|
||||
StopHurting = true;
|
||||
_stopHurting = true;
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
StopHurting = false;
|
||||
_stopHurting = false;
|
||||
}
|
||||
|
||||
IEnumerator Music()
|
||||
private IEnumerator PlaySfx()
|
||||
{
|
||||
float oldVolume = BackgroundMusic.volume;
|
||||
var oldVolume = BackgroundMusic.volume;
|
||||
|
||||
BackgroundMusic.volume = 0.25f;
|
||||
audioSFX.Play();
|
||||
_audioSfx.Play();
|
||||
|
||||
yield return new WaitForSeconds(3.0f);
|
||||
BackgroundMusic.volume = oldVolume;
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@ using System;
|
|||
|
||||
public class BirdBossHealthBar : MonoBehaviour
|
||||
{
|
||||
BirdBoss birdBoss;
|
||||
Animator animator;
|
||||
private BirdBoss _birdBoss;
|
||||
private Animator _animator;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
birdBoss = GetComponentInParent<BirdBoss>();
|
||||
animator = GetComponent<Animator>();
|
||||
animator.SetBool("100", true);
|
||||
_birdBoss = GetComponentInParent<BirdBoss>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_animator.SetBool("100", true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
int[] health = { 100, 75, 50, 25 };
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
animator.SetBool(health[i].ToString(), birdBoss.health >= health[i]);
|
||||
_animator.SetBool(health[i].ToString(), _birdBoss.health >= health[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 665915097276953698}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -0.701, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 733867154372970512}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &733867154069418475
|
||||
GameObject:
|
||||
|
|
@ -60,6 +60,7 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 733867154069418475}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 0.9, z: 1}
|
||||
|
|
@ -68,7 +69,6 @@ Transform:
|
|||
- {fileID: 733867154372970512}
|
||||
- {fileID: 8796774747485130469}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &733867154069418470
|
||||
MonoBehaviour:
|
||||
|
|
@ -112,7 +112,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
--- !u!50 &848612645191291936
|
||||
Rigidbody2D:
|
||||
serializedVersion: 4
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -123,10 +123,16 @@ Rigidbody2D:
|
|||
m_UseFullKinematicContacts: 0
|
||||
m_UseAutoMass: 0
|
||||
m_Mass: 1
|
||||
m_LinearDrag: 1.5
|
||||
m_AngularDrag: 0.05
|
||||
m_LinearDamping: 1.5
|
||||
m_AngularDamping: 0.05
|
||||
m_GravityScale: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_Interpolate: 0
|
||||
m_SleepingMode: 1
|
||||
m_CollisionDetection: 0
|
||||
|
|
@ -163,11 +169,32 @@ BoxCollider2D:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 733867154069418475}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_CompositeOperation: 0
|
||||
m_CompositeOrder: 0
|
||||
m_Offset: {x: -0.009941071, y: -0.1178202}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
|
|
@ -178,7 +205,6 @@ BoxCollider2D:
|
|||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.7017675, y: 1.913107}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!82 &5670231526534885764
|
||||
|
|
@ -192,6 +218,7 @@ AudioSource:
|
|||
serializedVersion: 4
|
||||
OutputAudioMixerGroup: {fileID: 0}
|
||||
m_audioClip: {fileID: 8300000, guid: aee0c13683235c84d8d0fe41081bc604, type: 3}
|
||||
m_Resource: {fileID: 8300000, guid: aee0c13683235c84d8d0fe41081bc604, type: 3}
|
||||
m_PlayOnAwake: 0
|
||||
m_Volume: 1
|
||||
m_Pitch: 1
|
||||
|
|
@ -302,6 +329,7 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 733867154372970519}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
|
|
@ -309,7 +337,6 @@ Transform:
|
|||
m_Children:
|
||||
- {fileID: 7831235675031236576}
|
||||
m_Father: {fileID: 733867154069418468}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &733867154372970514
|
||||
SpriteRenderer:
|
||||
|
|
@ -328,6 +355,9 @@ SpriteRenderer:
|
|||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
|
|
@ -365,7 +395,7 @@ SpriteRenderer:
|
|||
m_SpriteSortPoint: 0
|
||||
--- !u!95 &733867154372970513
|
||||
Animator:
|
||||
serializedVersion: 5
|
||||
serializedVersion: 7
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -379,6 +409,7 @@ Animator:
|
|||
m_ApplyRootMotion: 0
|
||||
m_LinearVelocityBlending: 0
|
||||
m_StabilizeFeet: 0
|
||||
m_AnimatePhysics: 0
|
||||
m_WarningMessage:
|
||||
m_HasTransformHierarchy: 1
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
|
|
@ -410,13 +441,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4406158393300619773}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: -2.5, z: 0}
|
||||
m_LocalScale: {x: 1.5, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 733867154069418468}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &1964016032722204993
|
||||
SpriteRenderer:
|
||||
|
|
@ -435,6 +466,9 @@ SpriteRenderer:
|
|||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
|
|
@ -472,7 +506,7 @@ SpriteRenderer:
|
|||
m_SpriteSortPoint: 0
|
||||
--- !u!95 &1005185907
|
||||
Animator:
|
||||
serializedVersion: 5
|
||||
serializedVersion: 7
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
|
|
@ -486,6 +520,7 @@ Animator:
|
|||
m_ApplyRootMotion: 0
|
||||
m_LinearVelocityBlending: 0
|
||||
m_StabilizeFeet: 0
|
||||
m_AnimatePhysics: 0
|
||||
m_WarningMessage:
|
||||
m_HasTransformHierarchy: 1
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class Aleksei : MonoBehaviour
|
|||
[Header("Speed")]
|
||||
public float NormalSpeed = 500f;
|
||||
public float FastSpeed = 700f;
|
||||
float speed = 500f;
|
||||
private float _speed = 500f;
|
||||
|
||||
[Header("Range")]
|
||||
public float range = 10f;
|
||||
|
|
@ -22,237 +22,249 @@ public class Aleksei : MonoBehaviour
|
|||
|
||||
[Header("Pathfinding")]
|
||||
public float nextWaypointDistance = 3f;
|
||||
int currentWaypoint = 0;
|
||||
private int _currentWaypoint;
|
||||
|
||||
[Header("Audio")]
|
||||
public AudioSource BackgroundMusic;
|
||||
private AudioSource audioSFX;
|
||||
private AudioSource _audioSfx;
|
||||
|
||||
[Header("Health")]
|
||||
public int health = 200;
|
||||
bool StopHurting = false;
|
||||
private bool _stopHurting;
|
||||
|
||||
[Header("GameObjects")]
|
||||
public GameObject deathEffect;
|
||||
public GameObject EnemyWeapon;
|
||||
|
||||
Path path;
|
||||
Seeker seeker;
|
||||
Transform player;
|
||||
Rigidbody2D rb;
|
||||
Animator animator;
|
||||
Transform enemyGFX;
|
||||
|
||||
[Header("Animation IDs")]
|
||||
private static readonly int AttackAnimationID = Animator.StringToHash("Attack");
|
||||
private static readonly int SwordAttackAnimationID = Animator.StringToHash("SwordAttack");
|
||||
private static readonly int DamageAnimationID = Animator.StringToHash("Damage");
|
||||
private static readonly int EnterStage2AnimationID = Animator.StringToHash("EnterStage2");
|
||||
|
||||
private Path _path;
|
||||
private Seeker _seeker;
|
||||
private Transform _player;
|
||||
private Rigidbody2D _rb;
|
||||
private Animator _animator;
|
||||
private Transform _enemyGfx;
|
||||
|
||||
public static float BulletCalcDirection;
|
||||
bool StopAttack = false;
|
||||
bool Attacking = false;
|
||||
bool isInStage2 = false;
|
||||
bool transitioningToStage2 = false;
|
||||
private bool _startGoing;
|
||||
private bool _stopAttack;
|
||||
private bool _attacking;
|
||||
private bool _isInStage2;
|
||||
private bool _transitioningToStage2;
|
||||
|
||||
void Start()
|
||||
public Aleksei(AudioSource audioSfx)
|
||||
{
|
||||
seeker = GetComponent<Seeker>();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
|
||||
audioSFX = GetComponent<AudioSource>();
|
||||
enemyGFX = GetComponentInChildren<SpriteRenderer>().transform;
|
||||
|
||||
speed = NormalSpeed;
|
||||
|
||||
InvokeRepeating("UpdatePath", 0f, .5f);
|
||||
_audioSfx = audioSfx;
|
||||
}
|
||||
|
||||
void UpdatePath()
|
||||
private void Start()
|
||||
{
|
||||
if (seeker.IsDone())
|
||||
_seeker = GetComponent<Seeker>();
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
_animator = GetComponentInChildren<Animator>();
|
||||
_player = GameObject.FindGameObjectWithTag("Player").transform;
|
||||
|
||||
_audioSfx = GetComponent<AudioSource>();
|
||||
_enemyGfx = GetComponentInChildren<SpriteRenderer>().transform;
|
||||
|
||||
_speed = NormalSpeed;
|
||||
_startGoing = false;
|
||||
|
||||
InvokeRepeating(nameof(UpdatePath), 0f, .5f);
|
||||
}
|
||||
|
||||
private void UpdatePath()
|
||||
{
|
||||
if (_seeker.IsDone())
|
||||
{
|
||||
seeker.StartPath(rb.position, player.position, OnPathComplete);
|
||||
_seeker.StartPath(_rb.position, _player.position, OnPathComplete);
|
||||
}
|
||||
}
|
||||
|
||||
void OnPathComplete (Path p)
|
||||
private void OnPathComplete (Path p)
|
||||
{
|
||||
if (!p.error)
|
||||
if (p.error)
|
||||
{
|
||||
path = p;
|
||||
currentWaypoint = 0;
|
||||
return;
|
||||
}
|
||||
_path = p;
|
||||
_currentWaypoint = 0;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (Pause.IsPause)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = Vector2.Distance(transform.position, player.position);
|
||||
if (distance < range && !Attacking && !transitioningToStage2)
|
||||
var distance = Vector2.Distance(transform.position, _player.position);
|
||||
if (distance < range && !_startGoing)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (currentWaypoint >= path.vectorPath.Count)
|
||||
_startGoing = true;
|
||||
}
|
||||
|
||||
if (_startGoing && !_attacking && !_transitioningToStage2)
|
||||
{
|
||||
if (_path == null || _currentWaypoint >= _path.vectorPath.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] -rb.position).normalized;
|
||||
Vector2 force = direction * speed * Time.deltaTime;
|
||||
Vector2 direction = ((Vector2)_path.vectorPath[_currentWaypoint] -_rb.position).normalized;
|
||||
Vector2 force = direction * (_speed * Time.deltaTime);
|
||||
|
||||
rb.AddForce(force);
|
||||
_rb.AddForce(force);
|
||||
|
||||
distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);
|
||||
distance = Vector2.Distance(_rb.position, _path.vectorPath[_currentWaypoint]);
|
||||
|
||||
if (distance < nextWaypointDistance)
|
||||
{
|
||||
currentWaypoint++;
|
||||
_currentWaypoint++;
|
||||
}
|
||||
|
||||
//You can make look it differently, if you delete 'rb.velocity' and add 'force' instead.
|
||||
if (rb.linearVelocity.x >= 0.01f)
|
||||
// Flip enemy sprite
|
||||
if (_rb.linearVelocity.x >= 0.01f)
|
||||
{
|
||||
enemyGFX.transform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
_enemyGfx.transform.localScale = new Vector3(-1f, 1f, 1f);
|
||||
BulletCalcDirection = 1f;
|
||||
}
|
||||
else if (rb.linearVelocity.x <= -0.01f)
|
||||
else if (_rb.linearVelocity.x <= -0.01f)
|
||||
{
|
||||
enemyGFX.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
_enemyGfx.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
BulletCalcDirection = -1f;
|
||||
}
|
||||
|
||||
if (distance < attackRange)
|
||||
{
|
||||
if (!StopAttack)
|
||||
if (!_stopAttack)
|
||||
{
|
||||
StartCoroutine(Attack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
distance = Vector2.Distance(transform.position, player.position);
|
||||
distance = Vector2.Distance(transform.position, _player.position);
|
||||
if (distance > range)
|
||||
{
|
||||
speed = FastSpeed;
|
||||
_speed = FastSpeed;
|
||||
}
|
||||
|
||||
/*if (Input.GetKeyDown(KeyCode.Q))
|
||||
{
|
||||
TakeDamage(20);
|
||||
}*/
|
||||
if (health <= 60 && !isInStage2)
|
||||
|
||||
if (health <= 60 && !_isInStage2)
|
||||
{
|
||||
StartCoroutine(GetToStage2());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
StartCoroutine(ColAttack());
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collider)
|
||||
private void OnTriggerEnter2D(Collider2D collider)
|
||||
{
|
||||
float distance = Vector2.Distance(transform.position, player.position);
|
||||
if (collider.gameObject.tag == "Bullet" && distance < range && !StopHurting)
|
||||
var distance = Vector2.Distance(transform.position, _player.position);
|
||||
if (collider.gameObject.CompareTag("Bullet") && distance < range && !_stopHurting)
|
||||
{
|
||||
TakeDamage(10);
|
||||
}
|
||||
}
|
||||
|
||||
// Health
|
||||
void TakeDamage(int damage)
|
||||
{
|
||||
if (!MainMenu.ExitLevel)
|
||||
{
|
||||
health -= damage;
|
||||
|
||||
//only animate damage if health is above 60 (not stage2)
|
||||
if (health > 60)
|
||||
{
|
||||
StartCoroutine(DamageAnimation());
|
||||
}
|
||||
|
||||
StartCoroutine(BulletAttacked());
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
//Die
|
||||
Instantiate(deathEffect, transform.position, Quaternion.identity);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Attack()
|
||||
private void TakeDamage(int damage)
|
||||
{
|
||||
StopAttack = true;
|
||||
if (MainMenu.ExitLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
health -= damage;
|
||||
|
||||
//only animate damage if health is above 60 (not stage2)
|
||||
if (health > 60)
|
||||
{
|
||||
StartCoroutine(AnimateDamage());
|
||||
}
|
||||
|
||||
StartCoroutine(BulletAttacked());
|
||||
|
||||
if (health <= 0)
|
||||
{
|
||||
//Die
|
||||
Instantiate(deathEffect, transform.position, Quaternion.identity);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Attack()
|
||||
{
|
||||
_stopAttack = true;
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
Attacking = true;
|
||||
animator.SetBool("Attack", true);
|
||||
_attacking = true;
|
||||
_animator.SetBool(AttackAnimationID, true);
|
||||
Instantiate(EnemyWeapon, firePoint.position, firePoint.rotation);
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
animator.SetBool("Attack", false);
|
||||
Attacking = false;
|
||||
_animator.SetBool(AttackAnimationID, false);
|
||||
_attacking = false;
|
||||
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
StopAttack = false;
|
||||
_stopAttack = false;
|
||||
}
|
||||
|
||||
IEnumerator ColAttack()
|
||||
private IEnumerator ColAttack()
|
||||
{
|
||||
animator.SetBool("SwordAttack", true);
|
||||
_animator.SetBool(SwordAttackAnimationID, true);
|
||||
Enemy.TookDamage = true;
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
animator.SetBool("SwordAttack", false);
|
||||
_animator.SetBool(SwordAttackAnimationID, false);
|
||||
}
|
||||
|
||||
IEnumerator DamageAnimation()
|
||||
private IEnumerator AnimateDamage()
|
||||
{
|
||||
animator.SetBool("Damage", true);
|
||||
_animator.SetBool(DamageAnimationID, true);
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
animator.SetBool("Damage", false);
|
||||
_animator.SetBool(DamageAnimationID, false);
|
||||
}
|
||||
|
||||
IEnumerator GetToStage2()
|
||||
private IEnumerator GetToStage2()
|
||||
{
|
||||
isInStage2 = true;
|
||||
_isInStage2 = true;
|
||||
|
||||
StopHurting = true;
|
||||
transitioningToStage2 = true;
|
||||
animator.SetBool("EnterStage2", true);
|
||||
_stopHurting = true;
|
||||
_transitioningToStage2 = true;
|
||||
_animator.SetBool(EnterStage2AnimationID, true);
|
||||
|
||||
StartCoroutine(Music());
|
||||
StartCoroutine(PlaySfx());
|
||||
NormalSpeed = FastSpeed;
|
||||
FastSpeed = stage2Speed;
|
||||
|
||||
yield return new WaitForSeconds(stage2AnimSec);
|
||||
animator.SetBool("EnterStage2", false);
|
||||
_animator.SetBool(EnterStage2AnimationID, false);
|
||||
|
||||
transitioningToStage2 = false;
|
||||
StopHurting = false;
|
||||
_transitioningToStage2 = false;
|
||||
_stopHurting = false;
|
||||
}
|
||||
|
||||
IEnumerator BulletAttacked()
|
||||
private IEnumerator BulletAttacked()
|
||||
{
|
||||
StopHurting = true;
|
||||
_stopHurting = true;
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
StopHurting = false;
|
||||
_stopHurting = false;
|
||||
}
|
||||
|
||||
IEnumerator Music()
|
||||
private IEnumerator PlaySfx()
|
||||
{
|
||||
float oldVolume = BackgroundMusic.volume;
|
||||
var oldVolume = BackgroundMusic.volume;
|
||||
BackgroundMusic.volume = 0.25f;
|
||||
|
||||
audioSFX.Play();
|
||||
_audioSfx.Play();
|
||||
yield return new WaitForSeconds(3.0f);
|
||||
BackgroundMusic.volume = oldVolume;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,25 @@ using UnityEngine.UI;
|
|||
|
||||
public class AlekseiHealthBar : MonoBehaviour
|
||||
{
|
||||
Aleksei aleksei;
|
||||
Animator animator;
|
||||
int NewHealth = 100;
|
||||
private Aleksei _aleksei;
|
||||
private Animator _animator;
|
||||
private int _newHealth = 100;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
aleksei = GetComponentInParent<Aleksei>();
|
||||
animator = GetComponent<Animator>();
|
||||
animator.SetBool("100", true);
|
||||
_aleksei = GetComponentInParent<Aleksei>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_animator.SetBool("100", true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
NewHealth = (aleksei.health * 100) / 200;
|
||||
_newHealth = (_aleksei.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(), health[i] == _newHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,26 +5,25 @@ using UnityEngine;
|
|||
public class BulletCalc : MonoBehaviour
|
||||
{
|
||||
public float speed = 20f;
|
||||
public int damage = 40;
|
||||
public GameObject impactEffect;
|
||||
public Vector3 desiredRotation = new Vector3(0f, 0f, 24f);
|
||||
Rigidbody2D rb;
|
||||
private Rigidbody2D _rb;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
|
||||
Vector3 rotation = desiredRotation;
|
||||
rotation.z = rotation.z * -Aleksei.BulletCalcDirection;
|
||||
rotation.z *= -Aleksei.BulletCalcDirection;
|
||||
|
||||
rb.linearVelocity = transform.right * Aleksei.BulletCalcDirection * speed;
|
||||
_rb.linearVelocity = transform.right * Aleksei.BulletCalcDirection * speed;
|
||||
transform.rotation = Quaternion.Euler(rotation);
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collision)
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Enemy.TookDamage = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,11 +85,12 @@ public class Ali : MonoBehaviour
|
|||
|
||||
private void OnPathComplete (Path p)
|
||||
{
|
||||
if (!p.error)
|
||||
if (p.error)
|
||||
{
|
||||
_path = p;
|
||||
_currentWaypoint = 0;
|
||||
return;
|
||||
}
|
||||
_path = p;
|
||||
_currentWaypoint = 0;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
|
|
@ -99,8 +100,8 @@ public class Ali : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
|
||||
float distance = Vector2.Distance(transform.position, _player.position);
|
||||
if (distance < range)
|
||||
var distance = Vector2.Distance(transform.position, _player.position);
|
||||
if (distance < range && !_startGoing)
|
||||
{
|
||||
_startGoing = true;
|
||||
}
|
||||
|
|
@ -290,7 +291,7 @@ public class Ali : MonoBehaviour
|
|||
|
||||
private IEnumerator PlaySfx()
|
||||
{
|
||||
float oldVolume = BackgroundMusic.volume;
|
||||
var oldVolume = BackgroundMusic.volume;
|
||||
BackgroundMusic.volume = 0.25f;
|
||||
_audioSfx.Play();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,25 +5,25 @@ using UnityEngine.UI;
|
|||
|
||||
public class AliHealthBar : MonoBehaviour
|
||||
{
|
||||
Ali ali;
|
||||
Animator animator;
|
||||
int NewHealth = 100;
|
||||
private Ali _ali;
|
||||
private Animator _animator;
|
||||
private int _newHealth = 100;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
ali = GetComponentInParent<Ali>();
|
||||
animator = GetComponent<Animator>();
|
||||
animator.SetBool("100", true);
|
||||
_ali = GetComponentInParent<Ali>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_animator.SetBool("100", true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
NewHealth = (ali.health * 100) / 200;
|
||||
_newHealth = (_ali.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(), health[i] == _newHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,23 @@ using UnityEngine;
|
|||
public class BulletAli : MonoBehaviour
|
||||
{
|
||||
public float speed = 20f;
|
||||
public int damage = 40;
|
||||
public GameObject impactEffect;
|
||||
Rigidbody2D rb;
|
||||
SpriteRenderer spriteRenderer;
|
||||
private Rigidbody2D _rb;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
GetComponent<SpriteRenderer>();
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
Vector3 newScale = transform.localScale;
|
||||
|
||||
newScale.x *= Ali.BulletAliDirection;
|
||||
rb.linearVelocity = transform.right * Ali.BulletAliDirection * speed;
|
||||
_rb.linearVelocity = transform.right * Ali.BulletAliDirection * speed;
|
||||
transform.localScale = newScale;
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D collision)
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Player")
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Enemy.TookDamage = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue