Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public enum enemyState
- {
- idle,
- walk,
- attack,
- stagger
- }
- public class Enemy : MonoBehaviour
- {
- [Header("State Machine")]
- public enemyState currentState;
- [Header("Health")]
- public FloatValue maxHealth;
- public float health;
- [Header("Stats")]
- public string enemyName;
- public int baseAttack;
- public float moveSpeed;
- [Header("Player Stats")]
- public int xpGain;
- public int levelUp;
- public GameObject playerLevelUp;
- //public int level = DBManager.level;
- [Header("Effects")]
- public GameObject deathEffect;
- private float deathEffectDelay = 1f;
- private void Awake()
- {
- health = maxHealth.InitialValue;
- }
- void TakeDamage(float damage)
- {
- health -= damage;
- if(health <= 0)
- {
- DeathEffect();
- this.gameObject.SetActive(false);
- }
- }
- private void DeathEffect()
- {
- if(deathEffect != null)
- {
- GameObject effect = Instantiate(deathEffect, transform.position, Quaternion.identity);
- Destroy(effect, deathEffectDelay);
- }
- }
- public void Knock(Rigidbody2D myrigidbody, float knockTime, float damage)
- {
- xpGain += DBManager.xp + 1;
- if(xpGain >= DBManager.level * DBManager.level * 100)
- {
- playerLevelUp.gameObject.SetActive(true);
- Debug.Log("You have Leveled Up");
- StartCoroutine(LevelUpCO());
- }
- StartCoroutine(XPAdd());
- Debug.Log("XP has Been Added");
- StartCoroutine(KnockCo(myrigidbody, knockTime));
- TakeDamage(damage);
- }
- IEnumerator KnockCo(Rigidbody2D myrigidbody, float knockTime)
- {
- if (myrigidbody != null)
- {
- yield return new WaitForSeconds(knockTime);
- myrigidbody.velocity = Vector2.zero;
- currentState = enemyState.idle;
- myrigidbody.velocity = Vector2.zero;
- }
- }
- IEnumerator XPAdd()
- {
- WWWForm form = new WWWForm();
- form.AddField("username", DBManager.username);
- form.AddField("xp", xpGain);
- //form.AddField("level", levelUp);
- WWW www = new WWW(DBManager.GetBaseURL() + "xpPlayer.php", form);
- yield return www;
- Debug.Log(www.text);
- }
- private IEnumerator LevelUpCO()
- {
- yield return new WaitForSeconds(3);
- playerLevelUp.gameObject.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement