Limited movement when health <= 0
This commit is contained in:
parent
7ad703817c
commit
38540b2eab
@ -16,6 +16,11 @@ public class Player : MonoBehaviour
|
||||
private bool inRange = false;
|
||||
public ParticleSystem dmgParticleSystem;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
public float speedy = 300f;
|
||||
public Vector3 temp1;
|
||||
|
||||
public HealthBar healthBar;
|
||||
|
||||
private static bool attackSword;
|
||||
@ -33,7 +38,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private bool startRegen = false;
|
||||
|
||||
private bool canWalk = true;
|
||||
private bool canWalk;
|
||||
|
||||
[Header("Player Starts values")]
|
||||
public const int BaseHealth = 10;
|
||||
@ -74,6 +79,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
canWalk = true;
|
||||
Panel = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "YouDied").ToArray()[0];
|
||||
healthBar = (HealthBar)FindObjectOfType<HealthBar>();
|
||||
levelBar = (LevelBar)FindObjectOfType<LevelBar>();
|
||||
@ -303,12 +309,18 @@ public class Player : MonoBehaviour
|
||||
startRegen = false;
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
x = transform.position.x;
|
||||
y = transform.position.y;
|
||||
temp1.x = x;
|
||||
temp1.y = y;
|
||||
transform.position = Vector3.MoveTowards(transform.position, temp1, speedy * Time.deltaTime);
|
||||
if (isPanelEnabled)
|
||||
{
|
||||
Panel.SetActive(true);
|
||||
}
|
||||
walkSpeed = 0f;
|
||||
canWalk = false;
|
||||
gameObject.GetComponent<Animator>().enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +342,8 @@ public class Player : MonoBehaviour
|
||||
if (attackFist)
|
||||
{
|
||||
myAnimator.SetTrigger("attackFist");
|
||||
} else if (attackSword &&
|
||||
}
|
||||
else if (attackSword &&
|
||||
EquipmentUIManager.Instance.GetList().Count() != 0 &&
|
||||
EquipmentUIManager.Instance.GetList()
|
||||
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.WeaponSlot && el.Value != null).Count() > 0 &&
|
||||
@ -379,6 +392,17 @@ public class Player : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
walkSpeed = 0f;
|
||||
PlayerPrefs.SetFloat("speed", 0.0f);
|
||||
temp1.x = x;
|
||||
temp1.y = y;
|
||||
transform.position = Vector3.MoveTowards(transform.position, temp1, speedy * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
if (lvlUp == true)
|
||||
{
|
||||
@ -459,8 +483,21 @@ public class Player : MonoBehaviour
|
||||
HandleInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
walkSpeed = 0f;
|
||||
PlayerPrefs.SetFloat("speed", 0.0f);
|
||||
temp1.x = x;
|
||||
temp1.y = y;
|
||||
transform.position = Vector3.MoveTowards(transform.position, temp1, speedy * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (canWalk == true)
|
||||
{
|
||||
if (inputHorizontal != 0 || inputVertical != 0)
|
||||
@ -482,6 +519,8 @@ public class Player : MonoBehaviour
|
||||
ResetValues();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SaveCheckpoint()
|
||||
{
|
||||
currentHealth = PlayerPrefs.GetFloat("health");
|
||||
@ -537,7 +576,8 @@ public class Player : MonoBehaviour
|
||||
attackValue = attackCalculator.Calculate(equippedItem.Value);
|
||||
|
||||
PlayerPrefs.SetFloat("attackValue", attackValue);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("Attack Calculation Error");
|
||||
}
|
||||
@ -566,7 +606,8 @@ public class Player : MonoBehaviour
|
||||
if (EquipmentUIManager.Instance.GetList().Count() == 0 ||
|
||||
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null).Count() == 0 &&
|
||||
EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).Count() == 0
|
||||
){
|
||||
)
|
||||
{
|
||||
|
||||
defenseValue = defenseCalculator.CalculateWithoutItem();
|
||||
|
||||
@ -583,7 +624,8 @@ public class Player : MonoBehaviour
|
||||
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).Count() > 0 &&
|
||||
EquipmentUIManager.Instance.GetList()
|
||||
.Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.ArmorSlot && el.Value != null).First().Value.EquipmentType == EquipmentTypeEnum.Chest)
|
||||
) {
|
||||
)
|
||||
{
|
||||
var helmetSlot = EquipmentUIManager.Instance.GetList().Where(el => el.Key == (int)EquipmentPanelSlotsTypeEnum.HelmetSlot && el.Value != null);
|
||||
var helmet = (helmetSlot.Count() != 0) ? helmetSlot.First().Value.Value : 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user