Unity 2d 回血道具的實現

目錄

一、製作草莓預製體

二、設置玩家剛體組件的碰撞檢測永不休眠

三、給草莓添加動畫

四、給拾取草莓的動作添加粒子系統特效(小星星)

五、最後給草莓綁定collect腳本即可

一、製作草莓預製體

選擇圖片

添加碰撞盒、設爲觸發器

做成預製體

二、設置玩家剛體組件的碰撞檢測永不休眠

 

三、給草莓添加動畫

改變scale

第一幀

第二幀

按這個

這樣就都動了

效果

四、給拾取草莓的動作添加粒子系統特效(小星星)

-》

雙擊添加點

五、最後給草莓綁定collect腳本即可

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Collect : MonoBehaviour
{
    public ParticleSystem collectEffect;
 
    public AudioClip collectClip;
    // Start is called before the first frame update
    void Start()
    {
        
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
 
    private void OnTriggerEnter2D(Collider2D other)
    {
        PlayerControl pc = other.GetComponent<PlayerControl>();
        if(pc!=null)
        {
            if(pc.MyCurrentHealth<pc.MyMaxHealth)
            {
                pc.chnageHealth(1);
                Instantiate(collectEffect, transform.position, Quaternion.identity);
                AudioManager.instance.AudioPlay(collectClip);
                Destroy(this.gameObject);
                
            }
            Debug.Log("玩家碰到了草莓!");
        }
    }
}

 

附完整教程:

Unity2d Rubys Adventure 課程設計報告

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章