Unity类银河恶魔城学习记录11-15 p117 Ice and Fire item Effect源代码

2024-04-01 05:36

本文主要是介绍Unity类银河恶魔城学习记录11-15 p117 Ice and Fire item Effect源代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码


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

IceAndFire_Controller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class IceAndFire_Controller : ThurderStrike_Controller
{protected override void OnTriggerEnter2D(Collider2D collision){base.OnTriggerEnter2D(collision);}
}

ThurderStrike_Controller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ThurderStrike_Controller : MonoBehaviour
{protected virtual void OnTriggerEnter2D(Collider2D collision){if(collision.GetComponent<Enemy>()!= null){PlayerStats playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();EnemyStats enemyTarget = collision.GetComponent<EnemyStats>(); playerStats.DoMagicaDamage(enemyTarget);}}
}
IceAndFire_Effect.cs
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 iceAndFirePrufab;[SerializeField] private float xVelocity;public override void ExecuteEffect(Transform _respawPosition){Player player = PlayerManager.instance.player;bool thirdAttack = player.GetComponent<Player>().primaryAttack.comboCounter == 2;//设置第三下平a产生火球if (thirdAttack)//设置第三下平a产生火球{GameObject newIceAndFire = Instantiate(iceAndFirePrufab, _respawPosition.position, player.transform.rotation);//使火球旋转方向与player对齐newIceAndFire.GetComponent<Rigidbody2D>().velocity = new Vector2(xVelocity*player.facingDir,0);//获得速度并使其朝向与player一致Destroy(newIceAndFire, 10);// 自动销毁10秒}}
}

ThurderStrike_Effect.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;[CreateAssetMenu(fileName = "Thurder strike effect", menuName = "Data/Item effect/Thurder strike")]
public class ThurderStrike_Effect : ItemEffect
{[SerializeField] private GameObject thurderStrikePrefab;public override void ExecuteEffect(Transform _enemyPosition){GameObject newThurderStrike = Instantiate(thurderStrikePrefab,_enemyPosition.position,Quaternion.identity);Destroy(newThurderStrike, 1);}
}
PlayerPrimaryAttack.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class PlayerPrimaryAttackState : PlayerState
{//p38 2.从ground进入public int comboCounter { get; private set; }private float lastTimeAttacked;//距离上一次攻击的时间private float comboWindow = 2;//可以间隔的时间public PlayerPrimaryAttackState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName){}public override void Enter(){base.Enter();xInput = 0;//修复攻击乱转的问题if(comboCounter >2||Time.time>comboWindow+lastTimeAttacked)//当计数器超过2和间隔时间大于window时,进入第一个攻击动作{comboCounter = 0;}player.anim.SetInteger("ComboCounter", comboCounter);//设置animtor里的comboCounter#region 选择攻击方向float attackDir = player.facingDir;if(xInput != 0){attackDir = xInput;}#endregion//使其能改变攻击方向player.SetVelocity(player.attackMovement[comboCounter].x * attackDir, player.attackMovement[comboCounter].y);//给角色初速度,让角色在攻击触发时移动一点stateTimer = .1f;}public override void Exit(){base.Exit();player.StartCoroutine("BusyFor", .15f);comboCounter++;lastTimeAttacked = Time.time;}public override void Update(){base.Update();if(stateTimer<0){player.SetZeroVelocity();}//1.修改移动时攻击时后可以移动的BUG//2.但给了点时间模拟惯性可以动一点if (triggerCalled){stateMachine.ChangeState(player.idleState);}}
}
PlayerAnimationTrigger.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class playerAnimationTriggers : MonoBehaviour
{private Player player => GetComponentInParent<Player>();//获得夫组件上的实际存在的Player组件private void AnimationTrigger(){player.AnimationTrigger();}private void AttackTrigger(){Collider2D[] colliders = Physics2D.OverlapCircleAll(player.attackCheck.position, player.attackCheckRadius);//创建一个碰撞器组,保存所有圈所碰到的碰撞器//https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Physics2D.OverlapCircleAll.htmlforeach(var hit in colliders)//https://blog.csdn.net/m0_52358030/article/details/121722077{if(hit.GetComponent<Enemy>()!=null){EnemyStats _target = hit.GetComponent<EnemyStats>();if(_target != null)//修复无敌人时触发DoDamge出错的bugplayer.stats.DoDamage(_target);//提供一个可以从player调用敌人受伤函数的入口,通过传入受伤敌人的组件if(Inventory.instance.GetEquipment(EquipmentType.Weapon) != null)Inventory.instance.GetEquipment(EquipmentType.Weapon).Effect(_target.transform);// hit.GetComponent<Enemy>().DamageImpact();}}}private void ThrowSword(){SkillManager.instance.sword.CreateSword();}
}

这篇关于Unity类银河恶魔城学习记录11-15 p117 Ice and Fire item Effect源代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/866323

相关文章

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

统一返回JsonResult踩坑的记录

《统一返回JsonResult踩坑的记录》:本文主要介绍统一返回JsonResult踩坑的记录,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录统一返回jsonResult踩坑定义了一个统一返回类在使用时,JsonResult没有get/set方法时响应总结统一返回

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

java对接海康摄像头的完整步骤记录

《java对接海康摄像头的完整步骤记录》在Java中调用海康威视摄像头通常需要使用海康威视提供的SDK,下面这篇文章主要给大家介绍了关于java对接海康摄像头的完整步骤,文中通过代码介绍的非常详细,需... 目录一、开发环境准备二、实现Java调用设备接口(一)加载动态链接库(二)结构体、接口重定义1.类型

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

apache的commons-pool2原理与使用实践记录

《apache的commons-pool2原理与使用实践记录》ApacheCommonsPool2是一个高效的对象池化框架,通过复用昂贵资源(如数据库连接、线程、网络连接)优化系统性能,这篇文章主... 目录一、核心原理与组件二、使用步骤详解(以数据库连接池为例)三、高级配置与优化四、典型应用场景五、注意事

SpringBoot实现文件记录日志及日志文件自动归档和压缩

《SpringBoot实现文件记录日志及日志文件自动归档和压缩》Logback是Java日志框架,通过Logger收集日志并经Appender输出至控制台、文件等,SpringBoot配置logbac... 目录1、什么是Logback2、SpringBoot实现文件记录日志,日志文件自动归档和压缩2.1、

qtcreater配置opencv遇到的坑及实践记录

《qtcreater配置opencv遇到的坑及实践记录》我配置opencv不管是按照网上的教程还是deepseek发现都有些问题,下面是我的配置方法以及实践成功的心得,感兴趣的朋友跟随小编一起看看吧... 目录电脑环境下载环境变量配置qmake加入外部库测试配置我配置opencv不管是按照网上的教程还是de

使用nohup和--remove-source-files在后台运行rsync并记录日志方式

《使用nohup和--remove-source-files在后台运行rsync并记录日志方式》:本文主要介绍使用nohup和--remove-source-files在后台运行rsync并记录日... 目录一、什么是 --remove-source-files?二、示例命令三、命令详解1. nohup2.

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示