学习目标:
学习内容:
简单学习一下粒子系统
创建出点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
等我懂了再回来讲深一点