自学内容网 自学内容网

Unity类银河战士恶魔城学习总结(P117 Ice And Fire Item Effec 制作一把冰火属性的剑)

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

教程源地址:https://www.udemy.com/course/2d-rpg-alexdev/

制作一把双重属性的剑,我取名为冰与火之歌

 IceAndFire_Effect.cs

  • 这个脚本的作用是在玩家第三次攻击时生成一个冰火技能预制体,预制体会根据玩家的朝向以设定的速度向前飞行。
  • 该技能的核心特性是结合了玩家的连击次数(第三次连击时触发)和物理效果(通过 Rigidbody2D 控制速度)。
  • 生成的技能物体在 10 秒后自动销毁,以保持场景的清洁。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "Ice and Fire effect", menuName = "Data/Item effect/Ice and Fire")]
public class IceAndFire_Effect : ItemEffect
{
    [SerializeField] private GameObject iceAndFirePrefab;//冰火技能预制体
    [SerializeField] private float xVelocity;//冰火技能的水平速度

    public override void ExcuteEffect(Transform _respawnPositon)
    {
        Player player = PlayerManager.instance.player;

        bool thirdAttack =player.GetComponent<Player>().primaryAttack.comboCounter == 2;//第三次攻击才能释放冰火技能

        if (thirdAttack)
        {

            GameObject newIceAndFire = Instantiate(iceAndFirePrefab, _respawnPositon.position, player.transform.rotation);

            newIceAndFire.GetComponent<Rigidbody2D>().velocity = new Vector2 (xVelocity *player.facingDir,0);//修改朝向

            Destroy(newIceAndFire, 10);
        }    
    }
}

IceAndFire_Controller.cs

简单的覆盖碰撞触发器

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

public class IceAndFire_Controller : ThunderStrike_Controller
{
    protected override void OnTriggerEnter2D(Collider2D collision)
    {
        base.OnTriggerEnter2D(collision);
    }
}

PlayerAnimationTriggers.cs

using UnityEngine;

public class PlayerAnimationTriggers : MonoBehaviour
{
    private Player player => GetComponentInParent<Player>();

    private void AnimationTrigger()
    {
        player.AnimationTrigger();
    }

    private void AttackTrigger()//攻击触发函数
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(player.attackCheck.position, player.attackCheckRadius);//检测区域内的敌人

        foreach (var hit in colliders)//遍历检测到的对象
        {
            if (hit.GetComponent<Enemy>() != null)
            {
                EnemyStats _target = hit.GetComponent<EnemyStats>();//判断是否是敌人

                if (_target != null) //对敌人造成伤害
                    player.stats.DoDamage(_target);


                ItemData_Equipment weaponData = Inventory.instance.GetEquipment(EquipmentType.Weapon);

                if (weaponData != null)//应用武器特殊效果
                    weaponData.Effect(_target.transform);

            }
        }
    }


    private void ThrowSword()
    {
        SkillManager.instance.sword.CreateSword();
    }
}


原文地址:https://blog.csdn.net/suzh1qian/article/details/143634360

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!