【Unity2D】实现敌人掉血的粒子特效

学习目标:

各个参数参考翻译功能标准:Unity3D:粒子系统Particle System_nothing的专栏-CSDN博客_particle system1. GameObject → Create Other  →  Particle System。2. 选中 Particle System,可看到下列屬性:                         3.Particle System:                         Duration: 粒子发射时间(设定为5秒,每5秒发射一https://blog.csdn.net/azhou_hui/article/details/47159967?ops_request_misc=&request_id=&biz_id=102&utm_term=Unity%20partical%20system&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-47159967.first_rank_v2_pc_rank_v29&spm=1018.2226.3001.4187

参考视频:秦无邪OvO的个人空间_哔哩哔哩_Bilibili秦无邪OvO,独立游戏开发者/美术/编曲;秦无邪OvO的主页、动态、视频、专栏、频道、收藏、订阅等。哔哩哔哩Bilibili,你感兴趣的视频都在B站。icon-default.png?t=N7T8https://space.bilibili.com/335835274?from=search&seid=2940030192624790742&spm_id_from=333.337.0.0

学习内容:

简单学习一下粒子系统

创建出点Effects ——》partical systems即可创建


学习时间:

参数可以自己修改,根据我上面提到的参数翻译标准参考


再给这个游戏对象创建一个叫BloodEffect的C#脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BloodEffect : MonoBehaviour
{
    public float timeToDestory;
    void Start()
    {
        Destroy(gameObject, timeToDestory);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
用于定时销毁它

然后在Enemy脚本上调用它

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class Enemy : MonoBehaviour
{
    public int health;
    public int damage;
    public float changeTime;

    public GameObject bloodEffect;

    private SpriteRenderer sr;
    private Color originColor;
    public void Start()
    {
        sr = GetComponent<SpriteRenderer>();
        originColor = sr.color;
    }

    
    public void Update()
    {
        if(health <= 0)
        {
            Destroy(gameObject);
        }
    }
    public void TakeDamage(int damage)
    {
        health -= damage;
        FlashColor(changeTime);
        Instantiate(bloodEffect, 
            new Vector3(transform.position.x , transform.position.y + 0.5f, transform.position.z),
            Quaternion.identity);
    }

    void FlashColor(float time)
    {
        //分别对应着R,G,B,透明度
        sr.color = new Color(255, 255, 0, 255);
        Invoke("ResetColor", time);
    }

    void ResetColor()
    {
        sr.color = originColor;
    }
}
 

学习产出:

这样就爆橙汁了

但仍然需要深入了解Partical systems

等我懂了再回来讲深一点

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值