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 课程设计报告

猜你喜欢

转载自blog.csdn.net/weixin_43673589/article/details/106478243