类银河恶魔城 P18-8 Pop UP Text

 PopUpTextFX.cs

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class PopUpTextFX : MonoBehaviour
{
    private TextMeshPro myText;

    [SerializeField] private float speed;
    [SerializeField] private float disappearSpeed;
    [SerializeField] private float colorDisappearSpeed;

    [SerializeField] private float lifeTime;

    private float textTimer;
    void Start()
    {
        myText = GetComponent<TextMeshPro>();
        textTimer = lifeTime;
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = Vector2.MoveTowards(transform.position,new Vector2(transform.position.x,transform.position.y +1),speed*Time.deltaTime);
        textTimer-= Time.deltaTime;
        if (textTimer < 0)
        {
            float alpha = myText.color.a - colorDisappearSpeed * Time.deltaTime;
            myText.color = new Color(myText.color.r,myText.color.g,myText.color.b,alpha);

            if (myText.color.a < 50)
                speed = disappearSpeed;
            if(myText.color.a <= 0)
                Destroy(gameObject);
        }

    }
}

 CharacterStats.cs

    protected virtual void DecreaseHealthBy(int _damage)
    {
        if (isVulunerable)
            _damage = Mathf.RoundToInt(_damage * 1.1f);

        currentHealth -= _damage;
        if(_damage > 0)
            fx.CreatePopUpText(_damage.ToString());
        if(onHealthChanged != null)
            onHealthChanged();
    }

 PlayerGroundState.cs

    public override void Update()
    {
        base.Update();
        if (Input.GetKeyDown(KeyCode.R) && player.skill.blackhole.blackholeUnlocked)
        {
            if (player.skill.blackhole.cooldownTimer > 0)
            {
                player.fx.CreatePopUpText("Cooldown!");
                return;
            }
            stateMachine.ChangeState(player.blackhole);
        }
        //Debug.Log(HasNoSword());
        if (Input.GetKeyDown(KeyCode.Mouse1) )
        {
            if (HasNoSword() && player.skill.sword.swordUnlocked)
                stateMachine.ChangeState(player.aimSword);
        }

        if (Input.GetKeyDown(KeyCode.Q) && player.skill.parry.parryUnlocked)
        {
            stateMachine.ChangeState(player.counterAttack);
        }

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            stateMachine.ChangeState(player.primaryAttack);
        }

        //if (Input.GetKeyDown(KeyCode.LeftShift))
        //    stateMachine.ChangeState(player.dashState);
        if (player.IsGroundDetected() == false)
        {
            stateMachine.ChangeState(player.airState);
        }

        


        if (Input.GetKeyDown(KeyCode.Space) && player.IsGroundDetected())
        {
            stateMachine.ChangeState(player.jumpState);
        }
    }

 ItemObject.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemObject : MonoBehaviour
{
    //private SpriteRenderer sr;
    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private ItemData itemData;
    //[SerializeField] private Vector2 velocity;

    //private void Start()
    //{
    //    sr = GetComponent<SpriteRenderer>();

    //    sr.sprite = itemData.icon;
    //}

    //private void OnValidate()
    //{
    //    SetupVisuals();
    //}

    private void SetupVisuals()
    {
        if (itemData == null)
            return;

        GetComponent<SpriteRenderer>().sprite = itemData.icon;
        gameObject.name = "Item object -" + itemData.name;
    }

    //private void Update()
    //{
    //    if (Input.GetKeyDown(KeyCode.M))
    //        rb.velocity = velocity;
    //}

    public void SetupItem(ItemData _itemData, Vector2 _velocity)
    {
        itemData = _itemData;
        rb.velocity = _velocity;

        SetupVisuals();
    }

    public void PickupItem()
    {
        if (!Inventory.instance.CanAddItem() && itemData.itemType == ItemType.Equipment)
        {
            rb.velocity = new Vector2(0, 7);
            PlayerManager.instance.player.fx.CreatePopUpText("Inventory is full");
            return;
        }

        //AudioManager.instance.PlaySFX(4, transform);
        Inventory.instance.AddItem(itemData);
        Destroy(gameObject);
    }
}

 Skill.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Skill : MonoBehaviour
{
    public float cooldown;
    public float cooldownTimer;

    protected Player player;

    protected virtual void Start()
    {
        player = PlayerManager.instance.player;

        CheckUnlock();
    }

    protected virtual void Update()
    {
        cooldownTimer -= Time.deltaTime;
    }

    protected virtual void CheckUnlock()
    {

    }

    public virtual bool CanUseSkill()
    {
        if (cooldownTimer < 0)
        {

            UseSkill();
            cooldownTimer = cooldown;
            return true;
        }

        player.fx.CreatePopUpText("Cooldown");
        return false;
    }
    public virtual void UseSkill() {

        ;
    }

    protected virtual Transform FindClosestEnemy(Transform _checkTransform)
    {
        //closestEnemy = null; // 每次调用先重置
        Collider2D[] colliders = Physics2D.OverlapCircleAll(_checkTransform.position, 25);

        float closerDistance = Mathf.Infinity;

        Transform closetEnemy = null;

        foreach (var hit in colliders)
        {
            //if (hit.TryGetComponent<Enemy>(out var enemy))
            if (hit.GetComponent<Enemy>() != null)
            {
                float distanceToEnemy = Vector2.Distance(_checkTransform.position, hit.transform.position);

                if (distanceToEnemy < closerDistance)
                {
                    closerDistance = distanceToEnemy;
                }
                    closetEnemy = hit.transform; //新改0504
            }
        }
        return closetEnemy;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值