Added basic taking damage & dying system

This commit is contained in:
alilas2 2022-06-04 13:59:18 +02:00
parent bcfe2bf2e6
commit c65186b866
12 changed files with 10628 additions and 16 deletions

View File

@ -50,6 +50,7 @@
<Compile Include="Assets\Scripts\SettingsButton.cs" /> <Compile Include="Assets\Scripts\SettingsButton.cs" />
<Compile Include="Assets\Scripts\Enemies&apos; Scprits\Enemy.cs" /> <Compile Include="Assets\Scripts\Enemies&apos; Scprits\Enemy.cs" />
<Compile Include="Assets\Scripts\QuitGame.cs" /> <Compile Include="Assets\Scripts\QuitGame.cs" />
<Compile Include="Assets\NewGame.cs" />
<Compile Include="Assets\Scripts\Inventory\InventoryManager.cs" /> <Compile Include="Assets\Scripts\Inventory\InventoryManager.cs" />
<Compile Include="Assets\Scripts\Dialogue.cs" /> <Compile Include="Assets\Scripts\Dialogue.cs" />
<Compile Include="Assets\Scripts\Item\Item.cs" /> <Compile Include="Assets\Scripts\Item\Item.cs" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -0,0 +1,96 @@
fileFormatVersion: 2
guid: ac97e3c0c7bc4a646ac4a34d014d64e3
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ public class Enemy : MonoBehaviour
public string enemyName; public string enemyName;
public FloatValue maxHealth; public FloatValue maxHealth;
public float health; public float health;
public int baseAttack;
private void Awake() private void Awake()
{ {

View File

@ -15,6 +15,7 @@ public class FollowingEnemy : Enemy
public float roundingDistance; public float roundingDistance;
private Rigidbody2D myRigidbody; private Rigidbody2D myRigidbody;
public Animator anim; public Animator anim;
public GameObject other;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
@ -28,13 +29,29 @@ public class FollowingEnemy : Enemy
void Update() void Update()
{ {
CheckDistance(); CheckDistance();
//StartCoroutine(Timer());
} }
void CheckDistance() void CheckDistance()
{ {
if(Vector3.Distance(target.position, transform.position) <= chaseRadius) if(Vector3.Distance(target.position, transform.position) <= chaseRadius && Vector3.Distance(target.position, transform.position) > attackRadius)
{ {
transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime); transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
} }
} }
IEnumerator Timer()
{
DoDamage();
yield return new WaitForSeconds(1);
}
void DoDamage()
{
if (Vector3.Distance(target.position, transform.position) <= attackRadius)
{
int inRange = 1;
//other.GetComponent<Player>().TakeDamage(1);
}
}
} }

View File

@ -11,14 +11,43 @@ public class Player : MonoBehaviour
float speedLimiter = 0.7f; float speedLimiter = 0.7f;
float inputHorizontal; float inputHorizontal;
float inputVertical; float inputVertical;
public FloatValue currentHealth; public FloatValue maxHealth;
public float health;
private bool attack; private bool attack;
public GameObject Panel;
private bool inRange = false;
public ParticleSystem dmgParticleSystem;
void Start() void Start()
{ {
rb = gameObject.GetComponent<Rigidbody2D>(); rb = gameObject.GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>(); myAnimator = GetComponent<Animator>();
health = maxHealth.initialValue;
} }
public void TakeDamage(float damage)
{
health = health - damage;
var em = dmgParticleSystem.emission;
em.enabled = true;
StartCoroutine(Timer());
if (health <= 0)
{
Panel.SetActive(true);
}
}
IEnumerator Timer()
{
yield return new WaitForSeconds(0.2f);
var em = dmgParticleSystem.emission;
em.enabled = false;
}
private void HandleAttacks() private void HandleAttacks()
{ {
if (attack) if (attack)

51
Assets/TakingDamage.cs Normal file
View File

@ -0,0 +1,51 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TakingDamage : MonoBehaviour
{
private bool inRange = false;
public GameObject other;
private bool firstAttack = false;
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Enemy")
{
inRange = true;
firstAttack = false;
}
}
void OnTriggerExit2D(Collider2D collision)
{
inRange = false;
timer = 0f;
}
private float timer = 0f;
private float waitTime = 1.0f;
void Update()
{
if (inRange == true)
{
if(firstAttack == false)
{
if(timer >= 0.15f)
{
firstAttack = true;
other.GetComponent<Player>().TakeDamage(1.0f);
timer = 0f;
}
}
if (timer >= waitTime)
{
timer = 0f;
other.GetComponent<Player>().TakeDamage(1.0f);
}
timer += Time.deltaTime;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 06ef9e2571910444f908aebc64718459
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,6 +7,7 @@ TagManager:
- Pickable - Pickable
- SceneTransition - SceneTransition
- NPC - NPC
- Enemy
layers: layers:
- Default - Default
- TransparentFX - TransparentFX

View File

@ -24,17 +24,17 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe
flags: 0 flags: 0
RecentlyUsedScenePath-6: RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25 value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25
flags: 0 flags: 0
RecentlyUsedScenePath-9: RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
flags: 0 flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
vcSharedLogLevel: vcSharedLogLevel:
value: 0d5e400f0650 value: 0d5e400f0650
flags: 0 flags: 0