progress
This commit is contained in:
parent
6f66dd5023
commit
19fff3745e
BIN
Assets/.DS_Store
vendored
BIN
Assets/.DS_Store
vendored
Binary file not shown.
BIN
Assets/MultiplayerPrefab/.DS_Store
vendored
BIN
Assets/MultiplayerPrefab/.DS_Store
vendored
Binary file not shown.
|
|
@ -314,7 +314,7 @@ BoxCollider2D:
|
|||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: -0.1117599, y: 0.8405181}
|
||||
|
|
@ -347,6 +347,7 @@ MonoBehaviour:
|
|||
syncInterval: 0
|
||||
health: 100
|
||||
magicalHealth: 0
|
||||
shieldBreak: 0
|
||||
healthBar: {fileID: 3653340846896160726}
|
||||
MagicalhealthBar: {fileID: 3972942435470074426}
|
||||
speed: -0.65
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ BoxCollider2D:
|
|||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0.16937256, y: 0.6145453}
|
||||
|
|
@ -366,6 +366,7 @@ MonoBehaviour:
|
|||
syncInterval: 0
|
||||
health: 100
|
||||
magicalHealth: 0
|
||||
shieldBreak: 0
|
||||
healthBar: {fileID: 3653340846896160726}
|
||||
MagicalhealthBar: {fileID: 2197384177600481826}
|
||||
speed: -0.55
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ BoxCollider2D:
|
|||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0.045366943, y: 3.246708}
|
||||
|
|
@ -250,6 +250,7 @@ MonoBehaviour:
|
|||
syncInterval: 0
|
||||
health: 100
|
||||
magicalHealth: 0
|
||||
shieldBreak: 0
|
||||
healthBar: {fileID: 3653340846896160726}
|
||||
MagicalhealthBar: {fileID: 5662903864418491351}
|
||||
speed: -0.8
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ BoxCollider2D:
|
|||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: -0.23830795, y: 0.44725013}
|
||||
|
|
@ -283,6 +283,7 @@ MonoBehaviour:
|
|||
syncInterval: 0
|
||||
health: 100
|
||||
magicalHealth: 0
|
||||
shieldBreak: 0
|
||||
healthBar: {fileID: 3653340846896160726}
|
||||
MagicalhealthBar: {fileID: 6929609094885432149}
|
||||
speed: -0.5
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ BoxCollider2D:
|
|||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 0.31513762, y: 0.77473223}
|
||||
|
|
@ -347,6 +347,7 @@ MonoBehaviour:
|
|||
syncInterval: 0
|
||||
health: 100
|
||||
magicalHealth: 0
|
||||
shieldBreak: 0
|
||||
healthBar: {fileID: 3653340846896160726}
|
||||
MagicalhealthBar: {fileID: 2709162945487164275}
|
||||
speed: -0.5
|
||||
|
|
|
|||
|
|
@ -912,8 +912,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 0}
|
||||
m_AnchoredPosition: {x: 0.00012207031, y: 20}
|
||||
m_SizeDelta: {x: -0.00025510788, y: 30}
|
||||
m_AnchoredPosition: {x: 0.000061035156, y: 20}
|
||||
m_SizeDelta: {x: 0.00012207, y: 30}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &6875305720456407933
|
||||
MonoBehaviour:
|
||||
|
|
@ -9073,9 +9073,9 @@ RectTransform:
|
|||
- {fileID: 6834699274966114621}
|
||||
m_Father: {fileID: 288749914621996688}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0.5}
|
||||
m_AnchorMax: {x: 0, y: 0.5}
|
||||
m_AnchoredPosition: {x: 19.964722, y: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -512.0353, y: 0}
|
||||
m_SizeDelta: {x: 30, y: 30}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &5623080609460378711
|
||||
|
|
@ -9833,8 +9833,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -200, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: -178.037, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &8114871264030549166
|
||||
CanvasRenderer:
|
||||
|
|
@ -13203,8 +13203,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -326.67, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: -292.94977, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &6437560145585663992
|
||||
CanvasRenderer:
|
||||
|
|
@ -19127,8 +19127,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 180, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: 166.69412, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &9180523985572885400
|
||||
CanvasRenderer:
|
||||
|
|
@ -21201,8 +21201,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 53.33, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: 51.781, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &4521138676283010074
|
||||
CanvasRenderer:
|
||||
|
|
@ -34847,8 +34847,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -73.33, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: -63.124, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &3385706722609023602
|
||||
CanvasRenderer:
|
||||
|
|
@ -36103,7 +36103,7 @@ MonoBehaviour:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5334876594431442471}
|
||||
m_Enabled: 1
|
||||
m_Enabled: 0
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: cfabb0440166ab443bba8876756fdfa9, type: 3}
|
||||
m_Name:
|
||||
|
|
@ -36995,8 +36995,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -453.33, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: -407.853, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &7247761221542065640
|
||||
CanvasRenderer:
|
||||
|
|
@ -38522,8 +38522,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 561.29, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: 492.82718, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &6825953737906669211
|
||||
CanvasRenderer:
|
||||
|
|
@ -38546,7 +38546,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 0.4, g: 0.73333335, b: 0.41568628, a: 1}
|
||||
m_Color: {r: 0.4, g: 0.73333335, b: 0.41568628, a: 0}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
|
|
@ -39021,8 +39021,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 306.67, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: 281.60678, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &1671463973499466441
|
||||
CanvasRenderer:
|
||||
|
|
@ -39261,9 +39261,9 @@ RectTransform:
|
|||
- {fileID: 7854863165062211890}
|
||||
m_Father: {fileID: 288749914621996688}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0.5}
|
||||
m_AnchorMax: {x: 0, y: 0.5}
|
||||
m_AnchoredPosition: {x: 19.964844, y: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: -512.03516, y: 0}
|
||||
m_SizeDelta: {x: 30, y: 30}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &3746002634997393255
|
||||
|
|
@ -39352,8 +39352,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0.5}
|
||||
m_AnchorMax: {x: 1, y: 0.5}
|
||||
m_AnchoredPosition: {x: -2.7998047, y: 0}
|
||||
m_SizeDelta: {x: -49.190063, y: 16}
|
||||
m_AnchoredPosition: {x: -4.0448, y: 0}
|
||||
m_SizeDelta: {x: -46.7, y: 16}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &5990951506473996236
|
||||
GameObject:
|
||||
|
|
@ -57453,8 +57453,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 433.33, y: 0}
|
||||
m_SizeDelta: {x: 25, y: 25}
|
||||
m_AnchoredPosition: {x: 396.5109, y: 0}
|
||||
m_SizeDelta: {x: 22.68, y: 25}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &1598896423630024094
|
||||
CanvasRenderer:
|
||||
|
|
|
|||
|
|
@ -134,4 +134,4 @@ public class PlayerAttack : NetworkBehaviour{
|
|||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,11 @@ public class enemyScript : NetworkBehaviour
|
|||
public int health;
|
||||
[SyncVar(hook = nameof(OnMagicalHealthChange))]
|
||||
public int magicalHealth;
|
||||
|
||||
// NEW: Shield break boolean
|
||||
[SyncVar]
|
||||
public bool shieldBreak = false;
|
||||
|
||||
public SpriteHealthBar healthBar;
|
||||
public SpriteHealthBar MagicalhealthBar;
|
||||
public float speed;
|
||||
|
|
@ -40,63 +45,73 @@ public class enemyScript : NetworkBehaviour
|
|||
|
||||
MeshRenderer meshRenderer;
|
||||
public GameObject hitVfx;
|
||||
void Awake(){
|
||||
void Awake()
|
||||
{
|
||||
meshRenderer = GetComponent<MeshRenderer>();
|
||||
scanCooldown = Random.Range(0.5f, 1.5f);
|
||||
}
|
||||
private void Start(){
|
||||
rb2 = GetComponent<Rigidbody2D>();
|
||||
private void Start()
|
||||
{
|
||||
rb2 = GetComponent<Rigidbody2D>();
|
||||
//target = GameObject.FindWithTag("Player").transform;
|
||||
UpdateAnimation(directionString,animationString);
|
||||
defaultPos = transform.position;
|
||||
UpdateAnimation(directionString, animationString);
|
||||
defaultPos = transform.position;
|
||||
|
||||
}
|
||||
[SyncVar(hook =nameof(OnLevelChanged))]
|
||||
[SyncVar(hook = nameof(OnLevelChanged))]
|
||||
public int level;
|
||||
void OnLevelChanged(int oldVal, int newVal){
|
||||
if(isServer){return;}
|
||||
void OnLevelChanged(int oldVal, int newVal)
|
||||
{
|
||||
if (isServer) { return; }
|
||||
|
||||
SetLevel(newVal);
|
||||
}
|
||||
public void SetLevel(int _level){
|
||||
public void SetLevel(int _level)
|
||||
{
|
||||
|
||||
if(enemyLevel != null){
|
||||
enemyLevel.text = _level.ToString();
|
||||
if (enemyLevel != null)
|
||||
{
|
||||
enemyLevel.text = _level.ToString();
|
||||
}
|
||||
|
||||
|
||||
level = _level;
|
||||
int healthIncrement =level * HEALTH_INC;
|
||||
int healthIncrement = level * HEALTH_INC;
|
||||
maxHealth = 100 + healthIncrement;
|
||||
|
||||
health = (int)maxHealth;
|
||||
magicalHealth = (int)maxHealth;
|
||||
enemyAttackDamage += (int)(level * DAMAGE_INC);
|
||||
|
||||
// MODIFIED: Reset shield break when level is set
|
||||
shieldBreak = false;
|
||||
|
||||
// Debug.Log($"{health}/{maxHealth}");
|
||||
|
||||
|
||||
}
|
||||
public Vector3 defScale;
|
||||
Vector3 defaultPos;
|
||||
|
||||
|
||||
float playerDistCheckTimer=0f;
|
||||
void LateUpdate(){
|
||||
float playerDistCheckTimer = 0f;
|
||||
void LateUpdate()
|
||||
{
|
||||
LOD();
|
||||
}
|
||||
public const float disappearDistFromPlayer = 15f;
|
||||
void LOD(){
|
||||
if(playerDistCheckTimer > 0){playerDistCheckTimer -= Time.deltaTime;return;}
|
||||
void LOD()
|
||||
{
|
||||
if (playerDistCheckTimer > 0) { playerDistCheckTimer -= Time.deltaTime; return; }
|
||||
|
||||
playerDistCheckTimer = Random.Range(1.5f,2.5f);
|
||||
if(playerNetwork.localPlayerTransform == null){return;}
|
||||
playerDistCheckTimer = Random.Range(1.5f, 2.5f);
|
||||
if (playerNetwork.localPlayerTransform == null) { return; }
|
||||
float distToPlayer = Vector3.Distance(playerNetwork.localPlayerTransform.position, transform.position);
|
||||
meshRenderer.enabled = distToPlayer < disappearDistFromPlayer;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_SERVER || UNITY_EDITOR
|
||||
#if UNITY_SERVER || UNITY_EDITOR
|
||||
[Server]
|
||||
private void Update(){
|
||||
private void Update()
|
||||
{
|
||||
|
||||
// animator.skeleton.SetSkin
|
||||
// set animation state to running if in chase Range
|
||||
|
|
@ -104,54 +119,67 @@ public class enemyScript : NetworkBehaviour
|
|||
|
||||
// isInChaseRange = Physics2D.OverlapCircle(transform.position, chaseRadius , layerMask);
|
||||
// isInAttackRange = Physics2D.OverlapCircle(transform.position, attackRadius, layerMask);
|
||||
if (health <= 0 ){
|
||||
|
||||
// MODIFIED: Check both health and magicalHealth for death condition
|
||||
if (health <= 0 || (shieldBreak && magicalHealth <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(target != null){
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
isInChaseRange = Vector3.Distance(transform.position, target.transform.position) < chaseRadius;
|
||||
isInAttackRange = Vector3.Distance(transform.position, target.transform.position) < attackRadius;
|
||||
}else{
|
||||
isInAttackRange = Vector3.Distance(transform.position, target.transform.position) < attackRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
isInChaseRange = false;
|
||||
isInAttackRange = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
ScanPlayers();
|
||||
if(target !=null){
|
||||
if (target != null)
|
||||
{
|
||||
enemyFollow();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
float scanTimer =0;
|
||||
#endif
|
||||
float scanTimer = 0;
|
||||
float scanCooldown;
|
||||
public void ScanPlayers(){
|
||||
|
||||
if(scanTimer >0){scanTimer-=Time.deltaTime; return;}
|
||||
public void ScanPlayers()
|
||||
{
|
||||
|
||||
if (scanTimer > 0) { scanTimer -= Time.deltaTime; return; }
|
||||
|
||||
scanTimer = scanCooldown;
|
||||
playerNetwork[] playersinNetwork = FindObjectsOfType<playerNetwork>();
|
||||
float closestDist = float.MaxValue;
|
||||
playerNetwork closestPlayer = null;
|
||||
|
||||
foreach(playerNetwork player in playersinNetwork ){
|
||||
if(player.health <= 0 ){continue;}
|
||||
foreach (playerNetwork player in playersinNetwork)
|
||||
{
|
||||
if (player.health <= 0) { continue; }
|
||||
float dist = Vector3.Distance(transform.position, player.transform.position);
|
||||
if(dist < closestDist){
|
||||
if (dist < closestDist)
|
||||
{
|
||||
closestPlayer = player;
|
||||
closestDist = dist;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(closestDist < chaseRadius){
|
||||
target = closestPlayer ;
|
||||
if (closestDist < chaseRadius)
|
||||
{
|
||||
target = closestPlayer;
|
||||
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
target = null;
|
||||
}
|
||||
|
||||
|
||||
//if(target == null) {return;}
|
||||
|
||||
}
|
||||
|
|
@ -160,79 +188,99 @@ public class enemyScript : NetworkBehaviour
|
|||
// void RpcUpdateAnim(string animDir , string animName, bool isLoop){
|
||||
// UpdateAnimation(animDir , animName, isLoop);
|
||||
// }
|
||||
[SyncVar(hook =nameof(OnFlipped))]
|
||||
bool isFlipped= false;
|
||||
[SyncVar(hook = nameof(OnFlipped))]
|
||||
bool isFlipped = false;
|
||||
|
||||
void OnFlipped(bool oldVal, bool newVal){
|
||||
if(isServer){return;}
|
||||
transform.localScale = new Vector3(defScale.x * (newVal ? -1 : 1),defScale.y,defScale.z);
|
||||
void OnFlipped(bool oldVal, bool newVal)
|
||||
{
|
||||
if (isServer) { return; }
|
||||
transform.localScale = new Vector3(defScale.x * (newVal ? -1 : 1), defScale.y, defScale.z);
|
||||
HandleFlip();
|
||||
}
|
||||
|
||||
void HandleFlip(){
|
||||
if(uiEnemy == null){
|
||||
return;
|
||||
void HandleFlip()
|
||||
{
|
||||
if (uiEnemy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(transform.localScale.x < 0 ){
|
||||
uiEnemy.localScale = new Vector3(-1,1,1);
|
||||
if (transform.localScale.x < 0)
|
||||
{
|
||||
uiEnemy.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
else{
|
||||
uiEnemy.localScale = new Vector3(1,1,1);
|
||||
else
|
||||
{
|
||||
uiEnemy.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void enemyFollow(){
|
||||
|
||||
if(Mathf.Abs(dir.y) > Mathf.Abs(dir.x)){
|
||||
if(dir.y < 0){
|
||||
private void enemyFollow()
|
||||
{
|
||||
|
||||
if (Mathf.Abs(dir.y) > Mathf.Abs(dir.x))
|
||||
{
|
||||
if (dir.y < 0)
|
||||
{
|
||||
directionString = "Back";
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
directionString = "Front";
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
directionString = "Side";
|
||||
|
||||
if(dir.x < 0){
|
||||
transform.localScale = new Vector3(defScale.x,defScale.y,0);
|
||||
isFlipped=false;
|
||||
}else{
|
||||
transform.localScale = new Vector3(-defScale.x,defScale.y,0);
|
||||
if (dir.x < 0)
|
||||
{
|
||||
transform.localScale = new Vector3(defScale.x, defScale.y, 0);
|
||||
isFlipped = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localScale = new Vector3(-defScale.x, defScale.y, 0);
|
||||
isFlipped = true;
|
||||
}
|
||||
HandleFlip();
|
||||
}
|
||||
if(animationHistory != directionString + animationString){
|
||||
if (animationHistory != directionString + animationString)
|
||||
{
|
||||
UpdateAnimation(directionString, animationString);
|
||||
// RpcUpdateAnim(directionString, animationString,true);
|
||||
}
|
||||
animationHistory=directionString + animationString;
|
||||
animationHistory = directionString + animationString;
|
||||
|
||||
if(target != null){
|
||||
if (target != null)
|
||||
{
|
||||
dir = transform.position - target.transform.position;
|
||||
}
|
||||
|
||||
float angle = Mathf.Atan2(dir.y , dir.x ) * Mathf.Rad2Deg;
|
||||
|
||||
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
|
||||
dir.Normalize();
|
||||
|
||||
movement = dir;
|
||||
|
||||
if(rotate){
|
||||
if (rotate)
|
||||
{
|
||||
//set anim direction x, y dir
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
string animationHistory ="";
|
||||
[SyncVar(hook =nameof(OnAnimationDirectionChanged))]
|
||||
string animationHistory = "";
|
||||
[SyncVar(hook = nameof(OnAnimationDirectionChanged))]
|
||||
public string directionString = "Side";
|
||||
[SyncVar(hook =nameof(OnAnimationNameChanged))]
|
||||
[SyncVar(hook = nameof(OnAnimationNameChanged))]
|
||||
public string animationString = "Idle";
|
||||
|
||||
void OnAnimationDirectionChanged(string oldVal, string newVal){
|
||||
void OnAnimationDirectionChanged(string oldVal, string newVal)
|
||||
{
|
||||
UpdateAnimation(newVal, animationString);
|
||||
}
|
||||
|
||||
void OnAnimationNameChanged(string oldVal, string newVal){
|
||||
void OnAnimationNameChanged(string oldVal, string newVal)
|
||||
{
|
||||
UpdateAnimation(directionString, newVal);
|
||||
}
|
||||
|
||||
|
|
@ -241,67 +289,85 @@ public class enemyScript : NetworkBehaviour
|
|||
|
||||
[SyncVar]
|
||||
public float maxHealth;
|
||||
|
||||
#if UNITY_SERVER || UNITY_EDITOR
|
||||
|
||||
#if UNITY_SERVER || UNITY_EDITOR
|
||||
[Server]
|
||||
private void FixedUpdate() {
|
||||
if (health <= 0 || magicalHealth <= 0){
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// MODIFIED: Updated death condition
|
||||
if (health <= 0 || (shieldBreak && magicalHealth <= 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
healthBar.SetHealth(health, maxHealth);
|
||||
MagicalhealthBar.SetHealth(magicalHealth, maxHealth); //magical health maxout err
|
||||
if(isInChaseRange && !isInAttackRange ){
|
||||
MagicalhealthBar.SetHealth(magicalHealth, maxHealth);
|
||||
|
||||
if (isInChaseRange && !isInAttackRange)
|
||||
{
|
||||
MoveEnemy(movement);
|
||||
//Set animation to moving
|
||||
animationString = "Walk";
|
||||
}
|
||||
if(isInAttackRange){
|
||||
if (isInAttackRange)
|
||||
{
|
||||
rb2.velocity = Vector2.zero;
|
||||
//Set animation to attack
|
||||
animationString = "Attack";
|
||||
|
||||
if(attackTimer < attackDuration){
|
||||
if (attackTimer < attackDuration)
|
||||
{
|
||||
attackTimer += Time.deltaTime;
|
||||
|
||||
}else{
|
||||
attackTimer = 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
attackTimer = 0;
|
||||
Attack();
|
||||
}
|
||||
|
||||
|
||||
//TODO: ATTACK HERE
|
||||
|
||||
}
|
||||
|
||||
if(!isInAttackRange && !isInChaseRange){
|
||||
if (!isInAttackRange && !isInChaseRange)
|
||||
{
|
||||
//SetAnimation to idle
|
||||
animationString = "Idle";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
public void Attack(){
|
||||
public void Attack()
|
||||
{
|
||||
target.TakeDamage(enemyAttackDamage);
|
||||
}
|
||||
private void MoveEnemy(Vector2 dir){
|
||||
private void MoveEnemy(Vector2 dir)
|
||||
{
|
||||
rb2.MovePosition((Vector2)transform.position + (dir * speed * Time.deltaTime));
|
||||
}
|
||||
void UpdateAnimation(string direction, string animationName){
|
||||
void UpdateAnimation(string direction, string animationName)
|
||||
{
|
||||
// try{
|
||||
StartCoroutine(CoroutineUpdateAnim(direction, animationName));
|
||||
}
|
||||
|
||||
IEnumerator CoroutineUpdateAnim(string direction, string animationName){
|
||||
while(animator == null){
|
||||
IEnumerator CoroutineUpdateAnim(string direction, string animationName)
|
||||
{
|
||||
while (animator == null)
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Debug.LogError("animator is null!");
|
||||
}
|
||||
while(animator.skeleton == null){
|
||||
while (animator.skeleton == null)
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Debug.LogError("animator skelton is null!");
|
||||
|
||||
}
|
||||
while(animator.AnimationState == null){
|
||||
while (animator.AnimationState == null)
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Debug.LogError("animator state is null!");
|
||||
|
||||
|
|
@ -316,90 +382,150 @@ public class enemyScript : NetworkBehaviour
|
|||
Debug.Log($"Updating enemy animation {direction}_{animationName}");
|
||||
}
|
||||
|
||||
[Command(requiresAuthority =false)]
|
||||
void CmdTakeDamage(int damage,uint id){
|
||||
takedmg(damage,id);
|
||||
[Command(requiresAuthority = false)]
|
||||
void CmdTakeDamage(int damage, uint id)
|
||||
{
|
||||
takedmg(damage, id);
|
||||
Debug.Log("Enemy Attack Recieved ");
|
||||
}
|
||||
public void TakeDamage(int damage, uint id){
|
||||
if(isServer){
|
||||
takedmg(damage,id);
|
||||
|
||||
public void TakeDamage(int damage, uint id)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
takedmg(damage, id);
|
||||
}
|
||||
else{
|
||||
CmdTakeDamage(damage,id);
|
||||
else
|
||||
{
|
||||
CmdTakeDamage(damage, id);
|
||||
}
|
||||
}
|
||||
|
||||
void takedmg(int damage,uint id){
|
||||
if(health<=0){return;}
|
||||
health -= damage;
|
||||
//hit vfx
|
||||
// GameObject newObject = Instantiate(hitVfx , transform.position , Quaternion.identity );
|
||||
// newObject.transform.localPosition = Vector3.zero;
|
||||
// newObject.transform.parent = transform;
|
||||
if(health<= 0 ){
|
||||
// MODIFIED: Completely rewritten damage system
|
||||
void takedmg(int damage, uint id)
|
||||
{
|
||||
if (health <= 0) { return; }
|
||||
|
||||
int finalDamage = damage;
|
||||
|
||||
// If shield is not broken, reduce damage by half and damage magical health
|
||||
if (!shieldBreak && magicalHealth > 0)
|
||||
{
|
||||
finalDamage = damage / 2;
|
||||
|
||||
// Calculate magical health damage based on player attack damage + enemy level
|
||||
int magicalDamage = damage + level;
|
||||
magicalHealth -= magicalDamage;
|
||||
|
||||
// Check if shield breaks
|
||||
if (magicalHealth <= 0)
|
||||
{
|
||||
shieldBreak = true;
|
||||
magicalHealth = 0;
|
||||
Debug.Log("Shield Broken!");
|
||||
}
|
||||
}
|
||||
|
||||
// Apply damage to health
|
||||
health -= finalDamage;
|
||||
|
||||
// Check for death
|
||||
if (health <= 0)
|
||||
{
|
||||
StartCoroutine(couroutineDeath());
|
||||
|
||||
foreach(playerNetwork player in FindObjectsOfType<playerNetwork>()){
|
||||
if(player.netId == id){
|
||||
|
||||
//This one attacked me
|
||||
foreach (playerNetwork player in FindObjectsOfType<playerNetwork>())
|
||||
{
|
||||
if (player.netId == id)
|
||||
{
|
||||
player.OnEnemyKilled(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.Log("Enemy Takes Damage ***");
|
||||
|
||||
|
||||
Debug.Log($"Enemy Takes Damage: {finalDamage} | Shield Broken: {shieldBreak} | Health: {health} | Magical Health: {magicalHealth}");
|
||||
}
|
||||
|
||||
[Command(requiresAuthority =false)]
|
||||
void CmdTakeMagicalDamage(int damage,uint id){
|
||||
takeMagicalDmg(damage,id);
|
||||
Debug.Log("Enemy Attack Recieved ");
|
||||
[Command(requiresAuthority = false)]
|
||||
void CmdTakeMagicalDamage(int damage, uint id)
|
||||
{
|
||||
takeMagicalDmg(damage, id);
|
||||
Debug.Log("Enemy Magical Attack Recieved ");
|
||||
}
|
||||
public void TakeMagicalDamage(int damage, uint id){
|
||||
if(isServer){
|
||||
takeMagicalDmg(damage,id);
|
||||
|
||||
public void TakeMagicalDamage(int damage, uint id)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
takeMagicalDmg(damage, id);
|
||||
}
|
||||
else{
|
||||
CmdTakeMagicalDamage(damage,id);
|
||||
else
|
||||
{
|
||||
CmdTakeMagicalDamage(damage, id);
|
||||
}
|
||||
}
|
||||
|
||||
void takeMagicalDmg(int damage,uint id){
|
||||
if(magicalHealth<=0){return;}
|
||||
magicalHealth -= damage;
|
||||
if(magicalHealth<= 0 ){
|
||||
// MODIFIED: Updated magical damage to use same system
|
||||
void takeMagicalDmg(int damage, uint id)
|
||||
{
|
||||
if (magicalHealth <= 0 && shieldBreak) { return; }
|
||||
|
||||
int finalDamage = damage;
|
||||
|
||||
// If shield is not broken, reduce damage by half and damage magical health
|
||||
if (!shieldBreak && magicalHealth > 0)
|
||||
{
|
||||
finalDamage = damage / 2;
|
||||
|
||||
// Calculate magical health damage based on player attack damage + enemy level
|
||||
int magicalDamage = damage + level;
|
||||
magicalHealth -= magicalDamage;
|
||||
|
||||
// Check if shield breaks
|
||||
if (magicalHealth <= 0)
|
||||
{
|
||||
shieldBreak = true;
|
||||
magicalHealth = 0;
|
||||
Debug.Log("Shield Broken!");
|
||||
}
|
||||
}
|
||||
|
||||
// Apply damage to health
|
||||
health -= finalDamage;
|
||||
|
||||
// Check for death
|
||||
if (health <= 0)
|
||||
{
|
||||
StartCoroutine(couroutineDeath());
|
||||
|
||||
foreach(playerNetwork player in FindObjectsOfType<playerNetwork>()){
|
||||
if(player.netId == id){
|
||||
|
||||
//This one attacked me
|
||||
foreach (playerNetwork player in FindObjectsOfType<playerNetwork>())
|
||||
{
|
||||
if (player.netId == id)
|
||||
{
|
||||
player.OnEnemyKilled(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.Log("Enemy Takes Damage ***");
|
||||
|
||||
|
||||
Debug.Log($"Enemy Takes Magical Damage: {finalDamage} | Shield Broken: {shieldBreak} | Health: {health} | Magical Health: {magicalHealth}");
|
||||
}
|
||||
|
||||
IEnumerator couroutineDeath(){
|
||||
|
||||
IEnumerator couroutineDeath()
|
||||
{
|
||||
|
||||
animationString = "Death";
|
||||
StartCoroutine(PopDisappearUI());
|
||||
UpdateAnimation(directionString , animationString);
|
||||
UpdateAnimation(directionString, animationString);
|
||||
// RpcUpdateAnim(directionString, animationString,false);
|
||||
Vector3 lootSpawnPos = transform.position;
|
||||
lootSpawnPos.z = GameManager.instance.LootSpawnPointsParent.GetChild(0).position.z;
|
||||
//instantiate loot item
|
||||
GameObject newLoot = Instantiate(GameManager.instance.GetRandomLoot(), lootSpawnPos, Quaternion.identity);
|
||||
|
||||
|
||||
NetworkServer.Spawn(newLoot);
|
||||
|
||||
yield return new WaitForSecondsRealtime(7);// dead corpse delay
|
||||
|
||||
|
||||
if (!isServer)
|
||||
{
|
||||
CmdDie();
|
||||
|
|
@ -408,66 +534,57 @@ public class enemyScript : NetworkBehaviour
|
|||
{
|
||||
GameManager.OnEnemyDeath(this, defaultPos);
|
||||
}
|
||||
|
||||
/* transform.position = defaultPos;
|
||||
health = (int)maxHealth;
|
||||
magicalHealth = (int)maxHealth;*/
|
||||
|
||||
//animationString = "Idle";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Command]
|
||||
void CmdDie()
|
||||
{
|
||||
GameManager.OnEnemyDeath(this,defaultPos);
|
||||
GameManager.OnEnemyDeath(this, defaultPos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnHealthChange(int oldVlaue, int newValue){
|
||||
healthBar.SetHealth(newValue,maxHealth);
|
||||
|
||||
public void OnHealthChange(int oldVlaue, int newValue)
|
||||
{
|
||||
healthBar.SetHealth(newValue, maxHealth);
|
||||
}
|
||||
public void OnMagicalHealthChange(int oldVlaue, int newValue){
|
||||
MagicalhealthBar.SetHealth(newValue,maxHealth);
|
||||
|
||||
public void OnMagicalHealthChange(int oldVlaue, int newValue)
|
||||
{
|
||||
MagicalhealthBar.SetHealth(newValue, maxHealth);
|
||||
}
|
||||
|
||||
//etc for ui Disspear coroutine
|
||||
IEnumerator PopDisappearUI(){
|
||||
Vector3 originalScale = uiEnemy.localScale;
|
||||
|
||||
// First, scale up slightly
|
||||
float popDuration = 0.15f;
|
||||
float elapsedTime = 0f;
|
||||
Vector3 popScale = originalScale * 1.2f;
|
||||
|
||||
while(elapsedTime < popDuration)
|
||||
IEnumerator PopDisappearUI()
|
||||
{
|
||||
float t = elapsedTime / popDuration;
|
||||
uiEnemy.localScale = Vector3.Lerp(originalScale, popScale, t);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Then scale down to zero quickly
|
||||
float shrinkDuration = 0.3f;
|
||||
elapsedTime = 0f;
|
||||
|
||||
while(elapsedTime < shrinkDuration)
|
||||
{
|
||||
float t = elapsedTime / shrinkDuration;
|
||||
// Use ease-in curve for faster shrinking
|
||||
float easedT = t * t;
|
||||
uiEnemy.localScale = Vector3.Lerp(popScale, Vector3.zero, easedT);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
uiEnemy.localScale = Vector3.zero;
|
||||
uiEnemy.gameObject.SetActive(false);
|
||||
}
|
||||
Vector3 originalScale = uiEnemy.localScale;
|
||||
|
||||
// First, scale up slightly
|
||||
float popDuration = 0.15f;
|
||||
float elapsedTime = 0f;
|
||||
Vector3 popScale = originalScale * 1.2f;
|
||||
|
||||
while (elapsedTime < popDuration)
|
||||
{
|
||||
float t = elapsedTime / popDuration;
|
||||
uiEnemy.localScale = Vector3.Lerp(originalScale, popScale, t);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Then scale down to zero quickly
|
||||
float shrinkDuration = 0.3f;
|
||||
elapsedTime = 0f;
|
||||
|
||||
while (elapsedTime < shrinkDuration)
|
||||
{
|
||||
float t = elapsedTime / shrinkDuration;
|
||||
// Use ease-in curve for faster shrinking
|
||||
float easedT = t * t;
|
||||
uiEnemy.localScale = Vector3.Lerp(popScale, Vector3.zero, easedT);
|
||||
elapsedTime += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
uiEnemy.localScale = Vector3.zero;
|
||||
uiEnemy.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user