国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity類銀河惡魔城學(xué)習(xí)記錄8-5 p81 Blackhole duration源代碼

這篇具有很好參考價(jià)值的文章主要介紹了Unity類銀河惡魔城學(xué)習(xí)記錄8-5 p81 Blackhole duration源代碼。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

Alex教程每一P的教程原代碼加上我自己的理解初步理解寫(xiě)的注釋,可供學(xué)習(xí)Alex教程的人參考 此代碼僅為較上一P有所改變的代碼、

【Unity教程】從0編程制作類銀河惡魔城游戲_嗶哩嗶哩_bilibili

Unity類銀河惡魔城學(xué)習(xí)記錄8-5 p81 Blackhole duration源代碼,類銀河城學(xué)習(xí)記錄,學(xué)習(xí),游戲引擎,類銀河,unity,C#文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-840855.html

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 List<KeyCode> KeyCodeList;

    private float maxSize;//最大尺寸
    private float growSpeed;//變大速度
    private float shrinkSpeed;//縮小速度
    private float blackholeTimer;

    private bool canGrow = true;//是否可以變大
    private bool canShrink;//縮小
    private bool canCreateHotKeys = true;專門控制后面進(jìn)入的沒(méi)法生成熱鍵
    private bool cloneAttackReleased;


    private int amountOfAttacks = 4;
    private float cloneAttackCooldown = .3f;
    private float cloneAttackTimer;

    private List<Transform> targets = new List<Transform>();
    private List<GameObject> createdHotKey = new List<GameObject>();

    public bool playerCanExitState { get; private set; }

    
    public void SetupBlackhole(float _maxSize,float _growSpeed,float _shrinkSpeed,int _amountOfAttacks,float _cloneAttackCooldown,float _blackholeDuration)
    {
        maxSize = _maxSize;
        growSpeed = _growSpeed;
        shrinkSpeed = _shrinkSpeed;
        amountOfAttacks = _amountOfAttacks;
        cloneAttackCooldown = _cloneAttackCooldown;
        blackholeTimer = _blackholeDuration;
    }

    private void Update()
    {
        blackholeTimer -= Time.deltaTime;
        cloneAttackTimer -= Time.deltaTime;

        if(blackholeTimer <= 0)
        {
            blackholeTimer = Mathf.Infinity;//防止重復(fù)檢測(cè)
            if (targets.Count > 0)//只有有target才釋放攻擊
            {
                ReleaseCloneAttack();//釋放攻擊
            }
            else
               
                FinishBlackholeAbility();//縮小黑洞
        }

        if (Input.GetKeyDown(KeyCode.R)&& targets.Count > 0)
        {
            ReleaseCloneAttack();
        }

        CloneAttackLogic();

        if (canGrow && !canShrink)
        {
            //這是控制物體大小的參數(shù)
            transform.localScale = Vector2.Lerp(transform.localScale, new Vector2(maxSize, maxSize), growSpeed * Time.deltaTime);
            //類似MoveToward,不過(guò)是放大到多少大小 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 <= 1f)
            {
                Destroy(gameObject);
            }
        }
    }

    private void ReleaseCloneAttack()
    {
        cloneAttackReleased = true;
        canCreateHotKeys = false;

        DestroyHotKeys();
        PlayerManager.instance.player.MakeTransprent(true);
    }

    private void CloneAttackLogic()
    {
        if (cloneAttackTimer < 0 && cloneAttackReleased&&amountOfAttacks>0)
        {
            cloneAttackTimer = cloneAttackCooldown;

            int randomIndex = Random.Range(0, targets.Count);


            //限制攻擊次數(shù)和設(shè)置攻擊偏移量
            float _offset;

            if (Random.Range(0, 100) > 50)
                _offset = 1.5f;
            else
                _offset = -1.5f;
 
            SkillManager.instance.clone.CreateClone(targets[randomIndex], new Vector3(_offset, 0, 0));
            amountOfAttacks--;


            if (amountOfAttacks <= 0)
            {
                Invoke("FinishBlackholeAbility", 0.5f);
            }
        }
    }

    private void FinishBlackholeAbility()
    {
        DestroyHotKeys();
        canShrink = true;
        cloneAttackReleased = false;
        playerCanExitState = true;
        
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.GetComponent<Enemy>()!=null)
        {
            collision.GetComponent<Enemy>().FreezeTime(true);
            CreateHotKey(collision);
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.GetComponent<Enemy>() != null)
        {
            collision.GetComponent<Enemy>().FreezeTime(false);
           
        }
    }

    private void CreateHotKey(Collider2D collision)
    {
        if(KeyCodeList.Count == 0)//當(dāng)所有的KeyCode都被去除,就不在創(chuàng)建實(shí)例
        {
            return;
        }

        if(!canCreateHotKeys)//這是當(dāng)角色已經(jīng)開(kāi)大了,不在創(chuàng)建實(shí)例
        {
            return;
        }
        
        //創(chuàng)建實(shí)例
        GameObject newHotKey = Instantiate(hotKeyPrefab, collision.transform.position + new Vector3(0, 2), Quaternion.identity);

        //將實(shí)例添加進(jìn)列表
        createdHotKey.Add(newHotKey);


        //隨機(jī)KeyCode傳給HotKey,并且傳過(guò)去一個(gè)毀掉一個(gè)
        KeyCode choosenKey = KeyCodeList[Random.Range(0, KeyCodeList.Count)];

        KeyCodeList.Remove(choosenKey);

        Blackhole_Hotkey_Controller newHotKeyScript = newHotKey.GetComponent<Blackhole_Hotkey_Controller>();

        newHotKeyScript.SetupHotKey(choosenKey, collision.transform, this);
    }
    public void AddEnemyToList(Transform _myEnemy)
    {
        targets.Add(_myEnemy);
    }

    //銷毀Hotkey
    private 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] private GameObject blackholePrefab;
    [Space]

    [SerializeField] private float blackholeDuration;
    [SerializeField] int amountOfAttacks = 4;
    [SerializeField] float cloneAttackCooldown = .3f;


    



    Blackhole_Skill_Controller currentBlackhole;

    public override bool CanUseSkill()
    {
        return base.CanUseSkill();
    }

    public override void UseSkill()
    {
        base.UseSkill();

        GameObject newBlackhole = Instantiate(blackholePrefab,player.transform.position,Quaternion.identity);

        currentBlackhole = newBlackhole.GetComponent<Blackhole_Skill_Controller>();

        currentBlackhole.SetupBlackhole(maxSize,growSpeed,shrinkSpeed,amountOfAttacks,cloneAttackCooldown,blackholeDuration);
    }

    protected override void Start()
    {
        base.Start();
    }

    protected override void Update()
    {
        base.Update();
    }

    public bool SkillCompleted()
    {
        if(currentBlackhole == null)
         return false;
        if (currentBlackhole.playerCanExitState)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
Player.cs
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class Player : Entity
{
    [Header("Attack Details")]
    public Vector2[] attackMovement;//每個(gè)攻擊時(shí)獲得的速度組
    public float counterAttackDuration = .2f;
    


    public bool isBusy{ get; private set; }//防止在攻擊間隔中進(jìn)入move
    //
    [Header("Move Info")]
    public float moveSpeed;//定義速度,與xInput相乘控制速度的大小
    public float jumpForce;
    public float swordReturnImpact;//在player里設(shè)置swordReturnImpact作為擊退的參數(shù)

    [Header("Dash Info")]
    [SerializeField] private float dashCooldown;
    private float dashUsageTimer;//為dash設(shè)置冷卻時(shí)間,在一定時(shí)間內(nèi)不能連續(xù)使用
    public float dashSpeed;//沖刺速度
    public float dashDuration;//持續(xù)時(shí)間
    public float dashDir { get; private set; }


    
    
    #region 定義States
    public PlayerStateMachine stateMachine { get; private set; }
    public PlayerIdleState idleState { get; private set; }
    public PlayerMoveState moveState { get; private set; }
    public PlayerJumpState jumpState { get; private set; }
    public PlayerAirState airState { get; private set; }
    public PlayerDashState dashState { get; private set; }
    public PlayerWallSlideState wallSlide { get; private set; }
    public PlayerWallJumpState wallJump { get; private set; }
    


    public PlayerPrimaryAttackState primaryAttack { get; private set; }
    public PlayerCounterAttackState counterAttack { get; private set; }

    public PlayerAimSwordState aimSword { get; private set; }
    public PlayerCatchSwordState catchSword { get; private set; }

    public PlayerBlackholeState blackhole { get; private set; }


    public SkillManager skill { get; private set; }
    public GameObject sword{ get; private set; }//聲明sword

   
    #endregion
    protected override void Awake()
    {

        base.Awake();
        stateMachine = new PlayerStateMachine();
        //通過(guò)構(gòu)造函數(shù),在構(gòu)造時(shí)傳遞信息
        idleState = new PlayerIdleState(this, stateMachine, "Idle");
        moveState = new PlayerMoveState(this, stateMachine, "Move");
        jumpState = new PlayerJumpState(this, stateMachine, "Jump");
        airState = new PlayerAirState(this, stateMachine, "Jump");
        dashState = new PlayerDashState(this, stateMachine, "Dash");
        wallSlide = new PlayerWallSlideState(this, stateMachine, "WallSlide");
        wallJump = new PlayerWallJumpState(this, stateMachine, "Jump");//wallJump也是Jump動(dòng)畫(huà)


        primaryAttack = new PlayerPrimaryAttackState(this, stateMachine, "Attack");
        counterAttack = new PlayerCounterAttackState(this, stateMachine, "CounterAttack");

        aimSword = new PlayerAimSwordState(this,stateMachine, "AimSword");
        catchSword = new PlayerCatchSwordState(this, stateMachine, "CatchSword");
        blackhole = new PlayerBlackholeState(this, stateMachine, "Jump");

        //this 就是 Player這個(gè)類本身
    }//Awake初始化所以State,為所有State傳入各自獨(dú)有的參數(shù),及animBool,以判斷是否調(diào)用此動(dòng)畫(huà)(與animatoin配合完成)
    protected override void Start()
    {
        base.Start();
        stateMachine.Initialize(idleState);
        skill = SkillManager.instance;

    }

    protected override void Update()//在mano中update會(huì)自動(dòng)刷新但其他沒(méi)有mano的不會(huì)故,需要在這個(gè)updata中調(diào)用其他腳本中的函數(shù)stateMachine.currentState.update以實(shí)現(xiàn) //stateMachine中的update

    {
        base.Update();
        stateMachine.currentState.Update();//反復(fù)調(diào)用CurrentState的Update函數(shù)
        CheckForDashInput();
        
    }
    public void AssignNewSword(GameObject _newSword)//保持創(chuàng)造的sword實(shí)例的函數(shù)
    {
        sword = _newSword;
    }

    public void CatchTheSword()//通過(guò)player的CatchTheSword進(jìn)入,及當(dāng)劍消失的瞬間進(jìn)入
    {
        stateMachine.ChangeState(catchSword);
        Destroy(sword);
    }
    
    public IEnumerator BusyFor(float _seconds)//https://www.zhihu.com/tardis/bd/art/504607545?source_id=1001
    {
        isBusy = true;
        yield return new WaitForSeconds(_seconds);
        isBusy = false;
    
    }//p39 4.防止在攻擊間隔中進(jìn)入move,通過(guò)設(shè)置busy值,在使用某些狀態(tài)時(shí),使其為busy為true,抑制其進(jìn)入其他state
     //IEnumertor本質(zhì)就是將一個(gè)函數(shù)分塊執(zhí)行,只有滿足某些條件才能執(zhí)行下一段代碼,此函數(shù)有StartCoroutine調(diào)用
    public void AnimationTrigger() => stateMachine.currentState.AnimationFinishTrigger();
    //從當(dāng)前狀態(tài)拿到AnimationTrigger進(jìn)行調(diào)用的函數(shù)

    public void CheckForDashInput()
    {

        
        if (IsWallDetected())
        {
            return;
        }//修復(fù)在wallslide可以dash的BUG
        if (Input.GetKeyDown(KeyCode.LeftShift) && skill.dash.CanUseSkill())//將DashTimer<0 的判斷 改成DashSkill里的判斷
        {

            
            dashDir = Input.GetAxisRaw("Horizontal");//設(shè)置一個(gè)值,可以將dash的方向改為你想要的方向而不是你的朝向
            if (dashDir == 0)
            {
                dashDir = facingDir;//只有當(dāng)玩家沒(méi)有控制方向時(shí)才使用默認(rèn)朝向
            }
            stateMachine.ChangeState(dashState);
        }

    }//將Dash切換設(shè)置成一個(gè)函數(shù),使其在所以情況下都能使用
    
   
    
}

PlayerBlackholeState.cs
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerBlackholeState : PlayerState
{
    private float flyTime = .4f;//飛行時(shí)間
    private bool skillUsed;//技能是否在被使用
    private float defaultGravity;

    public PlayerBlackholeState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void AnimationFinishTrigger()
    {
        base.AnimationFinishTrigger();
    }

    public override void Enter()
    {
        base.Enter();

        skillUsed = false;
        stateTimer = flyTime;
        defaultGravity = rb.gravityScale;
        rb.gravityScale = 0;
    }

    public override void Exit()
    {
        base.Exit();
        rb.gravityScale = defaultGravity;
        player.MakeTransprent(false);
    }

    public override void Update()
    {
        base.Update();

        //使角色釋放技能后能飛起來(lái)
        if (stateTimer > 0)
        {
            rb.velocity = new Vector2(0, 15);
        }

        if(stateTimer < 0)
        {
            rb.velocity = new Vector2(0, -.1f);

            if(!skillUsed)
            {
                if(player.skill.blackhole.CanUseSkill())//創(chuàng)建實(shí)體
                skillUsed = true;
            }
        }

        if(player.skill.blackhole.SkillCompleted())
        {
            stateMachine.ChangeState(player.airState);
        }
    }
    
    
}

到了這里,關(guān)于Unity類銀河惡魔城學(xué)習(xí)記錄8-5 p81 Blackhole duration源代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Unity組件的學(xué)習(xí)記錄

    扯點(diǎn)犢子,學(xué)習(xí)Unity已經(jīng)有一段時(shí)間了,對(duì)于一個(gè)一直做H5游戲的開(kāi)發(fā)者來(lái)說(shuō)接觸和學(xué)習(xí)3D游戲引擎是一個(gè)新的開(kāi)始,但是也沒(méi)有一開(kāi)始就決定寫(xiě)寫(xiě)博客,近來(lái)這個(gè)感覺(jué)愈加強(qiáng)烈,尤其在粗淺的認(rèn)為Unity引擎中組件的重要性以及本人對(duì)復(fù)雜的組件種類認(rèn)識(shí)了解不足導(dǎo)致在學(xué)做游

    2024年01月24日
    瀏覽(18)
  • Unity學(xué)習(xí)記錄——UI設(shè)計(jì)

    Unity學(xué)習(xí)記錄——UI設(shè)計(jì)

    ? 本文是中山大學(xué)軟件工程學(xué)院2020級(jí)3d游戲編程與設(shè)計(jì)的作業(yè)8 1.相關(guān)資源 ? 本次項(xiàng)目之中的人物模型來(lái)自Starter Assets - Third Person Character Controller | 必備工具 | Unity Asset Store ? 此處使用了以下路徑的 PlayerArmature 預(yù)制,這個(gè)預(yù)制人物模型可以進(jìn)行行走奔跑跳躍等動(dòng)作,很適合

    2024年02月04日
    瀏覽(56)
  • Unity Dots學(xué)習(xí)內(nèi)容記錄

    Unity Dots學(xué)習(xí)內(nèi)容記錄

    DOTS未來(lái)的潛力還是挺多的,目前已經(jīng)陸續(xù)有項(xiàng)目局部投入該技術(shù),追求硬件到軟件的極致性能。 主要是記錄下學(xué)習(xí)unity dots技術(shù)的過(guò)程吧。 DOTS全稱Data Oriented Tech Stack,面向數(shù)據(jù)的技術(shù)堆棧。 是由Unity的下面幾個(gè)技術(shù)棧組成 1.Entities(ECS,Entity-Component Data-System) 2.JobSytem(多線程作

    2024年04月15日
    瀏覽(28)
  • unity 場(chǎng)景烘培(邊學(xué)習(xí),邊記錄)

    unity 場(chǎng)景烘培(邊學(xué)習(xí),邊記錄)

    目錄 前言: 一、什么是場(chǎng)景渲染烘培? 二、為什么要對(duì)場(chǎng)景渲染烘培? 總結(jié): 場(chǎng)景烘培渲染這塊以前接觸很少,因?yàn)橐从袑iT的同事搞這塊,要么就是開(kāi)發(fā)2d游戲(完全不需要)。 現(xiàn)在換了一家小公司,自己需要獨(dú)立做這件事的時(shí)候,問(wèn)題就來(lái)了。(此前也烘培了幾個(gè)

    2024年02月10日
    瀏覽(19)
  • Unity學(xué)習(xí)記錄:制作雙屏垃圾分類小游戲

    Unity學(xué)習(xí)記錄:制作雙屏垃圾分類小游戲

    要實(shí)現(xiàn)的功能 游戲操作 在規(guī)定時(shí)間內(nèi),垃圾通過(guò)拖拽進(jìn)入正確垃圾桶的容器,垃圾在這里消失,飛入第二個(gè)屏上對(duì)應(yīng)垃圾桶的位置并實(shí)現(xiàn)加分和加時(shí)間的效果,垃圾拖拽進(jìn)入不正確的垃圾桶,垃圾會(huì)返回到原來(lái)的位置,同時(shí),相應(yīng)的時(shí)間也會(huì)減少 勝利和失敗的條件: 勝利:

    2024年02月03日
    瀏覽(19)
  • Unity Shader學(xué)習(xí)記錄(11) ——透明效果的實(shí)現(xiàn)方式

    Unity Shader學(xué)習(xí)記錄(11) ——透明效果的實(shí)現(xiàn)方式

    1 透明效果的兩種方法 透明是游戲中經(jīng)常要使用的一種效果。在實(shí)時(shí)渲染中要實(shí)現(xiàn)透明效果,通常會(huì)在渲染模型時(shí)控制它的透明通道(Alpha Channel)。當(dāng)開(kāi)啟透明混合后,當(dāng)一個(gè)物體被渲染到屏幕上時(shí),每個(gè)片元除了顏色值和深度值之外,它還有另一個(gè)屬性一一透明度。 當(dāng)透明度

    2024年02月07日
    瀏覽(24)
  • 【Unity AR】<PokemonGo> AR精靈制作學(xué)習(xí)記錄

    ??? 《寶可夢(mèng)GO》(pokemonGo)是一款能對(duì)現(xiàn)實(shí)世界中出現(xiàn)的寶可夢(mèng)進(jìn)行探索捕捉、戰(zhàn)斗以及交換的游戲。玩家可以通過(guò)智能手機(jī)在現(xiàn)實(shí)世界里發(fā)現(xiàn)寶可夢(mèng),進(jìn)行抓捕和戰(zhàn)斗。玩家作為寶可夢(mèng)訓(xùn)練師抓到的寶可夢(mèng)越多會(huì)變得越強(qiáng)大,從而有機(jī)會(huì)抓到更強(qiáng)大更稀有的寶可夢(mèng)。本次

    2024年04月28日
    瀏覽(22)
  • Unity3D學(xué)習(xí)記錄02——PloyBrush場(chǎng)景搭建

    Unity3D學(xué)習(xí)記錄02——PloyBrush場(chǎng)景搭建

    首先在Window-Package Manager里面搜索Poly Brush,下載后將URP的Shader樣例導(dǎo)入 ?導(dǎo)入后Asset文件夾下會(huì)有Sample的文件夾,在菜單欄 Tools-PolyBrush-PolyBrush Window 打開(kāi)窗口 這個(gè)窗口最上面的五個(gè),第一個(gè)是用來(lái)調(diào)整地形高低的,第二個(gè)是進(jìn)行柔化場(chǎng)景的,第三個(gè)是調(diào)整顏色的, 第四個(gè)可以

    2024年02月08日
    瀏覽(96)
  • Unity學(xué)習(xí)記錄4——視頻進(jìn)度條制作,視頻倍速、快進(jìn)及后退

    Unity學(xué)習(xí)記錄4——視頻進(jìn)度條制作,視頻倍速、快進(jìn)及后退

    1.使用AVPro Video插件,進(jìn)行制作 2.效果演示 ? ? 3.代碼

    2024年02月03日
    瀏覽(16)
  • Unity3D學(xué)習(xí)記錄03——Navigation智能導(dǎo)航地圖烘焙

    Unity3D學(xué)習(xí)記錄03——Navigation智能導(dǎo)航地圖烘焙

    首先還是在Package Manager中安裝AI Navigation 接著選擇我們場(chǎng)景的地面,右鍵,找到AI的NavMesh Surface,它會(huì)為我們的Ground添加一個(gè)叫NavMesh Surface的子物體 在Inspector窗口中可以看到它的詳細(xì)的參數(shù): 圖中的R,H為你人物的參數(shù),45°為你的人物可以爬行的最大角度 Agent Type里面可以改

    2024年02月08日
    瀏覽(28)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包