赞
踩
类上面添加一行
[CreateAssetMenu(fileName = "Bullet", menuName = "New Bullet", order = 1)]
作用在 Assets 文件夹下,鼠标右键,菜单栏中添加一个按钮项,菜单名为 menuName,并执行生成名为 fileName 的脚本,order 为按钮显示顺序
创建ScriptableObject类文件:
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- // 在 Assets 下添加菜单
- // fileName 生成名为 Bullet的脚本
- // menuName 菜单按钮名New Bullet
- // order 按钮显示顺序
- [CreateAssetMenu(fileName = "Bullet", menuName = "New Bullet", order = 1)]
- public class Bullet: ScriptableObject {
-
- // Bullet 类直接继承自 ScriptableObject
-
- // 子弹速度
- public int speed = 10;
-
- // 伤害数值
- public int damage = 5;
-
- // 子弹关联的特效
- public GameObject effectObj;
-
- public bool CompareSpeed(float _speed)
- {
- return speed > _speed;
- }
-
- }

在 Assets 下任意文件夹内,鼠标右键, Create -> New Bullet
在鼠标所在目录下,生成 Bullet.asset
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。