网站开发的一般流程是什么,镇江网站建设制作,查企业免费查询,企业如何做好网络推广Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释#xff0c;可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili Blackhole_Skill_Controller.cs
using System.Collections;
using System.C…Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili Blackhole_Skill_Controller.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;public class Blackhole_Skill_Controller : MonoBehaviour
{[SerializeField] private GameObject hotKeyPrefab;[SerializeField] private ListKeyCode KeyCodeList;private float maxSize;//最大尺寸private float growSpeed;//变大速度private float shrinkSpeed;//缩小速度private bool canGrow true;//是否可以变大private bool canShrink;//缩小private bool canCreateHotKeys true;专门控制后面进入的没法生成热键private bool cloneAttackReleased;private int amountOfAttacks 4;private float cloneAttackCooldown .3f;private float cloneAttackTimer;private ListTransform targets new ListTransform();private ListGameObject createdHotKey new ListGameObject();public void SetupBlackhole(float _maxSize,float _growSpeed,float _shrinkSpeed,int _amountOfAttacks,float _cloneAttackCooldown){maxSize _maxSize;growSpeed _growSpeed;shrinkSpeed _shrinkSpeed;amountOfAttacks _amountOfAttacks;cloneAttackCooldown _cloneAttackCooldown;}private void Update(){cloneAttackTimer - Time.deltaTime;if (Input.GetKeyDown(KeyCode.R)){ReleaseCloneAttack();}CloneAttackLogic();if (canGrow !canShrink){//这是控制物体大小的参数transform.localScale Vector2.Lerp(transform.localScale, new Vector2(maxSize, maxSize), growSpeed * Time.deltaTime);//类似MoveToward不过是放大到多少大小 https://docs.unity3d.com/cn/current/ScriptReference/Vector2.Lerp.html}if (canShrink){transform.localScale Vector2.Lerp(transform.localScale, new Vector2(0, 0), shrinkSpeed * Time.deltaTime);if (transform.localScale.x 0){Destroy(gameObject);}}}private void ReleaseCloneAttack(){cloneAttackReleased true;canCreateHotKeys false;DestroyHotKeys();}private void CloneAttackLogic(){if (cloneAttackTimer 0 cloneAttackReleased){cloneAttackTimer cloneAttackCooldown;int randomIndex Random.Range(0, targets.Count);//限制攻击次数和设置攻击偏移量float _offset;if (Random.Range(0, 100) 50)_offset 2;else_offset -2;SkillManager.instance.clone.CreateClone(targets[randomIndex], new Vector3(_offset, 0, 0));amountOfAttacks--;if (amountOfAttacks 0){canShrink true;cloneAttackReleased false;}}}private void OnTriggerEnter2D(Collider2D collision){if(collision.GetComponentEnemy()!null){collision.GetComponentEnemy().FreezeTime(true);CreateHotKey(collision);}}private void CreateHotKey(Collider2D collision){if(KeyCodeList.Count 0)//当所有的KeyCode都被去除就不在创建实例{return;}if(!canCreateHotKeys)//这是当角色已经开大了不在创建实例{return;}//创建实例GameObject newHotKey Instantiate(hotKeyPrefab, collision.transform.position new Vector3(0, 2), Quaternion.identity);//将实例添加进列表createdHotKey.Add(newHotKey);//随机KeyCode传给HotKey并且传过去一个毁掉一个KeyCode choosenKey KeyCodeList[Random.Range(0, KeyCodeList.Count)];KeyCodeList.Remove(choosenKey);Blackhole_Hotkey_Controller newHotKeyScript newHotKey.GetComponentBlackhole_Hotkey_Controller();newHotKeyScript.SetupHotKey(choosenKey, collision.transform, this);}public void AddEnemyToList(Transform _myEnemy){targets.Add(_myEnemy);}//销毁Hotkeyprivate void DestroyHotKeys(){if(createdHotKey.Count 0){return;}for (int i 0; i createdHotKey.Count; i){Destroy(createdHotKey[i]); }}
}Blackhole_Skill.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Blackhole_Skill : Skill
{[SerializeField]private float maxSize;//最大尺寸[SerializeField] private float growSpeed;//变大速度[SerializeField] private float shrinkSpeed;//缩小速度[SerializeField] int amountOfAttacks 4;[SerializeField] float cloneAttackCooldown .3f;[SerializeField] private GameObject blackholePrefab;public override bool CanUseSkill(){return base.CanUseSkill();}public override void UseSkill(){base.UseSkill();GameObject newBlackhole Instantiate(blackholePrefab);Blackhole_Skill_Controller newBlackholeScripts newBlackhole.GetComponentBlackhole_Skill_Controller();newBlackholeScripts.SetupBlackhole(maxSize,growSpeed,shrinkSpeed,amountOfAttacks,cloneAttackCooldown);}protected override void Start(){base.Start();}protected override void Update(){base.Update();}
}