Added basic taking damage & dying system
This commit is contained in:
parent
bcfe2bf2e6
commit
c65186b866
@ -50,6 +50,7 @@
|
||||
<Compile Include="Assets\Scripts\SettingsButton.cs" />
|
||||
<Compile Include="Assets\Scripts\Enemies' Scprits\Enemy.cs" />
|
||||
<Compile Include="Assets\Scripts\QuitGame.cs" />
|
||||
<Compile Include="Assets\NewGame.cs" />
|
||||
<Compile Include="Assets\Scripts\Inventory\InventoryManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Dialogue.cs" />
|
||||
<Compile Include="Assets\Scripts\Item\Item.cs" />
|
||||
|
BIN
Assets/Scene Sprites/Materials/sample.png
Normal file
BIN
Assets/Scene Sprites/Materials/sample.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
96
Assets/Scene Sprites/Materials/sample.png.meta
Normal file
96
Assets/Scene Sprites/Materials/sample.png.meta
Normal 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
@ -8,6 +8,7 @@ public class Enemy : MonoBehaviour
|
||||
public string enemyName;
|
||||
public FloatValue maxHealth;
|
||||
public float health;
|
||||
public int baseAttack;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
@ -15,6 +15,7 @@ public class FollowingEnemy : Enemy
|
||||
public float roundingDistance;
|
||||
private Rigidbody2D myRigidbody;
|
||||
public Animator anim;
|
||||
public GameObject other;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@ -28,13 +29,29 @@ public class FollowingEnemy : Enemy
|
||||
void Update()
|
||||
{
|
||||
CheckDistance();
|
||||
//StartCoroutine(Timer());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,43 @@ public class Player : MonoBehaviour
|
||||
float speedLimiter = 0.7f;
|
||||
float inputHorizontal;
|
||||
float inputVertical;
|
||||
public FloatValue currentHealth;
|
||||
public FloatValue maxHealth;
|
||||
public float health;
|
||||
private bool attack;
|
||||
public GameObject Panel;
|
||||
private bool inRange = false;
|
||||
public ParticleSystem dmgParticleSystem;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = gameObject.GetComponent<Rigidbody2D>();
|
||||
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()
|
||||
{
|
||||
if (attack)
|
||||
|
51
Assets/TakingDamage.cs
Normal file
51
Assets/TakingDamage.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/TakingDamage.cs.meta
Normal file
11
Assets/TakingDamage.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06ef9e2571910444f908aebc64718459
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -7,6 +7,7 @@ TagManager:
|
||||
- Pickable
|
||||
- SceneTransition
|
||||
- NPC
|
||||
- Enemy
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
@ -24,17 +24,17 @@ EditorUserSettings:
|
||||
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-6:
|
||||
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-7:
|
||||
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-8:
|
||||
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-9:
|
||||
RecentlyUsedScenePath-7:
|
||||
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-8:
|
||||
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
|
||||
flags: 0
|
||||
RecentlyUsedScenePath-9:
|
||||
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
|
||||
flags: 0
|
||||
vcSharedLogLevel:
|
||||
value: 0d5e400f0650
|
||||
flags: 0
|
||||
|
Loading…
Reference in New Issue
Block a user