学习游戏制作记录(合并更多的技能与技能树)8.23
1.合并水晶技能与技能树
Crystal_Skill脚本:
[SerializeField] private UI_SkillTreeSlot UnlockCrystalMirageButton;
[SerializeField] private UI_SkillTreeSlot UnlockCrystalExplodeButton;
[SerializeField] private UI_SkillTreeSlot UnlockCrystalButton;
public bool CrystalUnlocked;
[SerializeField] private UI_SkillTreeSlot UnlockCrystalMovingButton;
[SerializeField] private UI_SkillTreeSlot UnlockCrystalMultiButton;//为所有水晶技能添加一个按钮
private void UnlockCrystal()//判断技能树中是否解锁
{
if(UnlockCrystalButton.unlocked)
{
CrystalUnlocked = true;
}
}
private void UnlockCrystalExpolde()
{
if(UnlockCrystalExplodeButton.unlocked)
{
canExplode = true;
}
}
private void UnlockCloneInstead()
{
if(UnlockCrystalMirageButton.unlocked)
{
cloneInsteadCrystal=true;
}
}
private void UnlockCrystalMove()
{
if(UnlockCrystalMovingButton.unlocked)
{
canMoveToEnemy = true;
}
}
private void UnlockCrystalMulti()
{
if(UnlockCrystalMultiButton.unlocked)
{
canMultiStack = true;
}
}
protected override void Start()//同样的道理,添加监听事件
{
base.Start();
UnlockCrystalExplodeButton.GetComponent<Button>().onClick.AddListener(() => UnlockCrystalExpolde());
UnlockCrystalMirageButton.GetComponent<Button>().onClick.AddListener(() => UnlockCloneInstead());
UnlockCrystalButton.GetComponent<Button>().onClick.AddListener(() => UnlockCrystal());
UnlockCrystalMovingButton.GetComponent<Button>().onClick.AddListener(() => UnlockCrystalMove());
UnlockCrystalMultiButton.GetComponent<Button>().onClick.AddListener(()=>UnlockCrystalMulti());
}
Player脚本:
if(Input.GetKeyDown(KeyCode.F)&&skill.crystal.CrystalUnlocked) //只有解锁水晶技能才可以使用
{
skill.crystal.CanbeUsed();
}
2.合并闪避技能与技能树
创建Dodge_Skill脚本:
[Header("Dodge")]
[SerializeField] private UI_SkillTreeSlot UnlockDodgeButton;//同上
[SerializeField] private int evasionAmount;//提升闪避的数值大小
public bool DodgeUnlocked;
[Header("Mirage Dodge")]
[SerializeField] private UI_SkillTreeSlot UnlockMirrageDodgeButton;
public bool MirrageDodgeUnlocked;
protected override void Start()
{
base.Start();
UnlockDodgeButton.GetComponent<Button>().onClick.AddListener(() => UnlockDodge());
UnlockMirrageDodgeButton.GetComponent<Button>().onClick.AddListener(() => UnlockMirrageDodge());
}
private void UnlockDodge()
{
if(UnlockDodgeButton.unlocked)
{
player.state.evasion.AddModify(evasionAmount);//添加修饰器,改变角色闪避的属性
Inventory.instance.UpdataStatUI();//更新状态UI,从Inventory中提取的方法
DodgeUnlocked = true;
}
}
private void UnlockMirrageDodge()
{
if (UnlockMirrageDodgeButton.unlocked)
{
MirrageDodgeUnlocked= true;
}
}
public void CreateMirrageOnDodge()//创造克隆
{
if(MirrageDodgeUnlocked)
{
SkillManage.instance.clone.CreatClone(player.transform, new Vector3(2 * player.facingDir, 0));
}
}
CharacterState脚本:
public virtual void onEvasion()
{
}
private bool TargetCanAvoidAttack(CharactorState _target)
{
int totalEvasion=_target.evasion.GetValue()+_target.agility.GetValue();
if (isShocked)
totalEvasion += 20;
if(Random.Range(0,100)<totalEvasion)
{
_target.onEvasion();//调用目标的闪避函数
return true;
}
return false;
}
PlayerStats脚本:
public override void onEvasion()
{
Debug.Log("clone");
PlayerManage.instance.player.skill.dodge.CreateMirrageOnDodge();//判断是否可以使用幻影闪现技能
}
3.合并剑技能与技能树
Sword_Skill脚本:
[SerializeField] private UI_SkillTreeSlot SpinUnlockButton;//解锁旋转剑
[SerializeField] private UI_SkillTreeSlot PierceUnlockButton;//穿刺剑
[SerializeField] private UI_SkillTreeSlot BounceUnlockButton;//弹跳剑
[SerializeField] private UI_SkillTreeSlot SwordUnlockButton;//普通剑
public bool SwordUnlocked;
[Header("Passive info")]
[SerializeField] private UI_SkillTreeSlot TimeStopUnlockButton;//时停被动
public bool TimeStopUnlocked;
[SerializeField] private UI_SkillTreeSlot VolunerableUnlockButton;//破甲被动
public bool VolunerableUnlocked;
public void UnlockTimeStop()
{
if(TimeStopUnlockButton.unlocked)
{
TimeStopUnlocked = true;
swordType = SwordType.Regular;//设置剑的类型
}
}
public void UnlockSpin()
{
if(SpinUnlockButton.unlocked)
{
swordType = SwordType.Spin;
}
}
public void UnlockPierce()
{
if(PierceUnlockButton.unlocked)
{
swordType= SwordType.Pierce;
}
}
public void UnlockBounce()
{
if(BounceUnlockButton.unlocked)
{
swordType = SwordType.Bounce;
}
}
#endregion
public void UnlockVolunerable()
{
if(VolunerableUnlockButton.unlocked)
{ VolunerableUnlocked = true;
}
}
public void UnlockSword()
{
if(SwordUnlockButton.unlocked)
{
SwordUnlocked = true;
}
}
CharactorState脚本:
private bool isVolunerable;//判断玩家或敌人是否处于破甲状态
public void MakeForVolunerable(float _duration)//启动破甲协程
{
StartCoroutine(VolunerableForCorotine(_duration));
}
public IEnumerator VolunerableForCorotine(float _duration)//持续一段时间
{
isVolunerable = true;
yield return new WaitForSeconds(_duration);
isVolunerable = false;
}
protected virtual void DecreaseHealth(int _damage)
{
if(isVolunerable)//如果处于破甲则使受到伤害提高1.1倍
{
_damage = Mathf.RoundToInt(_damage * 1.1f);
}
currentHealth -= _damage;
if(onHealthChange != null)
{
onHealthChange();
}
}
Sword_Skill_Control脚本:
private void SwordSkillDamage(Enemy enemy)
{
EnemyStats enemyStats =enemy.GetComponent<EnemyStats>();
player.state.DoDamage(enemyStats);
if(player.skill.sword.TimeStopUnlocked)
enemy.FreezeTimeFor(freezeTimeDuration);//是否有时停的被动
if(player.skill.sword.VolunerableUnlocked)
{
enemyStats.MakeForVolunerable(freezeTimeDuration);//是否造成破甲
}
ItemData_Equipment itemAmulet = Inventory.instance.GetEquipment(EquipmentType.Amulet);
if (itemAmulet != null)
{
itemAmulet.Effect(enemy.transform);
}
}
PlayerGroundedState脚本:
if(Input.GetKeyDown(KeyCode.Mouse1)&&HasNoSword()&&_Player.skill.sword.SwordUnlocked)
{
_PlayerStateMachine.ChangeState(_Player.AimSword);//解锁普通剑才可以使用
4.合并克隆技能与技能树
Clone_Skill脚本:
public float AttackMultiplier;//用来设置的攻击倍率
[Header("clone Attack")]
[SerializeField] private UI_SkillTreeSlot CloneAttackUnlockButton;//克隆攻击按钮
public bool canAttack;
[SerializeField] private float CloneAttackMultiplier;//克隆攻击的倍率
[Header("Aggresive Clone")]
[SerializeField] private UI_SkillTreeSlot AggresiveCloneUnlockButton;//攻击性克隆
[SerializeField] private float AggresiveCloneMultiplier;
[Header("Multi Clone")]
[SerializeField] private UI_SkillTreeSlot MutiCloneUnlockButton;//多重克隆
[SerializeField] private float MutiCloneMultiplier;
[Header("Crystal Instead Clone")]
[SerializeField] private UI_SkillTreeSlot CrystalInsteadUnlockButton;//水晶代替克隆
public void UnlockCloneAttack()
{
if(CloneAttackUnlockButton.unlocked)
{
canAttack = true;//同时设置倍率
AttackMultiplier = CloneAttackMultiplier;
}
}
public void UnlockAggresiveClone()
{
if(AggresiveCloneUnlockButton.unlocked)
{
canApplyOnHitEffect = true;
AttackMultiplier = AggresiveCloneMultiplier;
}
}
public void UnlockMultiClone()
{
if(MutiCloneUnlockButton.unlocked)
{
canDuplicateClone = true;
AttackMultiplier = MutiCloneMultiplier;
}
}
public void UnlockCrystalInstead()
{
if(CrystalInsteadUnlockButton.unlocked)
{
canCrystalInsteadClone = true;
}
}
Clone_Skill_Control脚本:
private float attackMultiplier;//通过设置函数传递这个值
private void AttackTrigger()
{
Collider2D[] collider2Ds = Physics2D.OverlapCircleAll(attackCheck.position, attackCheckRadius);
foreach (var hit in collider2Ds)
{
if (hit.GetComponent<Enemy>() != null)
{
//player.state.DoDamage(hit.GetComponent<CharactorState>());
PlayerStats playerStats =player.GetComponent<PlayerStats>();
EnemyStats enemyStats =hit.GetComponent<EnemyStats>();
playerStats.CloneDoDamge(enemyStats, attackMultiplier);//克隆造成伤害
if(player.skill.clone.canApplyOnHitEffect)
{
ItemData_Equipment itemData_Equipment = Inventory.instance.GetEquipment(EquipmentType.Weapon);
if (itemData_Equipment != null)
{
itemData_Equipment.Effect(hit.transform);//克隆是否触发物品的独特效果
}
}
if (canDuplicateClone)
{
if(Random.Range(0,100)<chanceToDuplicateClone)
{
SkillManage.instance.clone.CreatClone(hit.transform,new Vector3(.5f*facingDir,0));
}
}
}
}
}
PlayerStats脚本:
public void CloneDoDamge(CharactorState _target,float attackmultiplier)
{
if (TargetCanAvoidAttack(_target))
{
return;
}
int totalDamage = damage.GetValue() + strength.GetValue();
if (attackmultiplier > 0)//附加倍率的伤害
totalDamage = Mathf.RoundToInt(totalDamage * attackmultiplier);
if (CanCrit())
{
totalDamage = CaculateCritDamage(totalDamage);
}
totalDamage = TargetCheckArmor(_target, totalDamage);
_target.TakeDamage(totalDamage);
DoMagicDamage(_target);
}
5.合并黑洞技能与技能树
Blackhole_Skill脚本:
[SerializeField] private UI_SkillTreeSlot BlackholeUnlockButton;//黑洞技能树的按钮
public bool BlackholeUnlocked { get; private set; }
protected override void Start()//设置
{
base.Start();
BlackholeUnlockButton.GetComponent<Button>().onClick.AddListener(()=>UnlockBlackHole());
}
public void UnlockBlackHole()
{
if(BlackholeUnlockButton.unlocked)
{
BlackholeUnlocked = true;
}
}
PlayerGroundedState脚本:
if(Input.GetKeyDown(KeyCode.R)&&_Player.skill.blackhole.BlackholeUnlocked)//解锁黑洞才可以使用
{
_PlayerStateMachine.ChangeState(_Player.blackholeState);
}