Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerManager : MonoBehaviour
- {
- AnimManager animManager;
- PlayerMovement playerMovement;
- public Fighter fighter;
- public Health target;
- public float horInput;
- public float vertInput;
- public float moveAmount;
- public static PlayerManager instance;
- public GameObject player;
- public PlayerWeapon DefultWeapon = null;
- public PlayerWeapon currentwep = null;
- public AnimatorOverrideController animatorOverride = null;
- [SerializeField] Transform handTrans;
- public string defultWeaponName = "Staff";
- public Item item;
- public GameObject enemy;
- public AIController aiController;
- // Start is called before the first frame update
- void Start()
- {
- aiController = GetComponent<AIController>();
- fighter = GetComponent<Fighter>();
- enemy = GameObject.FindWithTag("Enemy");
- target = GetComponent<Health>();
- animManager = GetComponent<AnimManager>();
- playerMovement = GetComponent<PlayerMovement>();
- instance = this;
- PlayerWeapon weapon = UnityEngine.Resources.Load<PlayerWeapon>(defultWeaponName);
- SpawnWeapon(currentwep);
- }
- // Update is called once per frame
- void Update()
- {
- if (target.isDead) return;
- EquipWeapon(currentwep);
- animManager.UpdateAnimValues(0, moveAmount);
- moveAmount = Mathf.Clamp01(Mathf.Abs(horInput) + Mathf.Abs(vertInput));
- AttackBehavior();
- }
- private void FixedUpdate()
- {
- if (Input.GetKeyDown(KeyCode.M))
- {
- InventoryManager.instance.AddItem(item);
- }
- if (Input.GetKeyDown(KeyCode.N))
- {
- InventoryManager.instance.RemoveItem(item);
- }
- }
- private void SpawnWeapon(PlayerWeapon weapon)
- {
- currentwep = weapon;
- Animator animator = GetComponent<Animator>();
- weapon.Spawn(handTrans, animator);
- var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
- if (animatorOverride != null)
- {
- animator.runtimeAnimatorController = animatorOverride;
- }
- else if (overrideController != null)
- {
- animator.runtimeAnimatorController = overrideController.runtimeAnimatorController;
- }
- }
- public void Hit()
- {
- animManager.Hit();
- float damage = GetComponent<BaseStats>().GetStat(Stat.Damage);
- if (currentwep.HasProjectile())
- {
- currentwep.LaunchProjectile(handTrans, target, gameObject, damage);
- }
- else
- {
- target.TakeDamage(gameObject, damage);
- }
- }
- public void Attack(GameObject combattarget)
- {
- target = combattarget.GetComponent<Health>();
- }
- public void EquipWeapon(PlayerWeapon weapon)
- {
- currentwep = weapon;
- Animator animator = GetComponent<Animator>();
- weapon.Spawn(handTrans, animator);
- }
- public IEnumerable<float> GetAddMod(Stat stat)
- {
- if (stat == Stat.Damage)
- {
- yield return currentwep.GetDamage();
- }
- }
- private void AttackBehavior()
- {
- Attack(enemy);
- }
- }
Add Comment
Please, Sign In to add comment