使用unity制作一个宝可梦——5.使用脚本对象创建宝可梦

《PonkemonBase.cs》
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Pokemon",menuName ="Pokemon/Create new pokemon")]
public class PokemonBase : ScriptableObject
{
[SerializeField] string name; //宝可梦的名字
[TextArea]
[SerializeField] string description; //描述
[SerializeField] Sprite frontSprite; //宝可梦的正面
[SerializeField] Sprite backSprite; //宝可梦的反面
[SerializeField] PokemonType Type1; //宝可梦的主系别
[SerializeField] PokemonType Type2; //宝可梦的副系别
[SerializeField] int maxHp; //最大生命值
[SerializeField] int attack; //攻击力
[SerializeField] int defense; //防御力
[SerializeField]int spAttack; //魔法攻击
[SerializeField]int spDefense; //魔法防御
[SerializeField]int speed; //速度值
public string GetName()
{
return name;
}
public string Description
{
get { return description; }
}
public int MaxHp
{
get { return maxHp; }
}
public int Attack
{
get { return attack; }
}
public int SpAttack
{
get { return spAttack; }
}
public int Defense
{
get { return defense; }
}
public int SpDefense
{
get { return spDefense; }
}
public int Speed
{
get { return speed; }
}
public string Name
{
get { return name; }
}
}
public enum PokemonType
{
None, //没有属性
Normal, //正常的
Fire, //火属性
Water, //水属性
Electric, //电气
Grass, //草系
Ice, //冰系
Fighting, //战斗系
Poison, //毒系
Ground, //土系
Flying, //飞行系
Psychic, //精神系
Bug, //虫系
Rock, //石系
Ghost, //鬼系
Dragon //龙系
}
《Pokemon.cs》
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pokemon
{
PokemonBase _base; //原始数据(父类)
int level; //等级
public Pokemon(PokemonBase pbase,int plevel)
{
_base = pbase;
level = plevel;
}
public int Attack //攻击力随等级成长的公式
{
get { return Mathf.FloorToInt((_base.Attack * level) / 100f) + 5; }
}
public int Defense //防御力随等级成长的公式
{
get { return Mathf.FloorToInt((_base.Defense * level) / 100f) + 5; }
}
public int SpAttack //魔攻随等级成长的公式
{
get { return Mathf.FloorToInt((_base.SpAttack * level) / 100f) + 5; }
}
public int SpDefense //魔抗随等级成长的公式
{
get { return Mathf.FloorToInt((_base.SpDefense * level) / 100f) + 5; }
}
public int Speed //速度随等级成长的公式
{
get { return Mathf.FloorToInt((_base.Speed * level) / 100f) + 5; }
}
public int MaxHp //防御力随等级成长的公式
{
get { return Mathf.FloorToInt((_base.MaxHp * level) / 100f) + 10; }
}
}