创建一个口袋妖怪游戏并尝试制作它,以便一旦它满足某个级别标准,就会在该级别解锁一个新动作以取代基本动作。 我试图公开 NewMoves 列表,因为我被告知这是错误的,但它没有帮助,并反复说它无法转换它们。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pokemon
{
Pokemon_Data _Data;
int level;
public int HP {get; set;}
[field: SerializeField] public List<NewMove> Moves {get; private set;}
public Pokemon(Pokemon_Data pData, int pLevel)
{
_Data = pData;
level = pLevel;
HP = _Data.MaxHP;
Moves = new List<NewMove>();
foreach (var move in _Data.NewMoves)
{
if (move.Level <= level)
Moves.Add(new Moves(move.Base));
if (Moves.Count >= 4)
break;
}
//Pokemon formula to calculate stat increase through levels
public int Attack
{
get{ return Mathf.FloorToInt((_Data.Attack * level) /100f) + 5; }
}
public int Defense
{
get{ return Mathf.FloorToInt((_Data.Defense * level) /100f) + 5; }
}
public int SpAttack
{
get{ return Mathf.FloorToInt((_Data.SpAttack * level) /100f) + 5; }
}
public int SpDefense
{
get{ return Mathf.FloorToInt((_Data.SpDefense * level) /100f) + 5; }
}
public int Speed
{
get{ return Mathf.FloorToInt((_Data.Speed * level) /100f) + 10; }
}
}
}
```
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Move", menuName = "Pokemon/Create new move") ]
public class Move_Data : ScriptableObject
{
[SerializeField] string name;
[TextArea]
[SerializeField] string description;
[SerializeField] PokemonType type;
[SerializeField] int power;
[SerializeField] int accuracy;
[SerializeField] int pp;
public string Name
{
get {return name;}
}
public string Description
{
get {return description;}
}
public PokemonType Type
{
get {return type;}
}
public int Power
{
get {return power;}
}
public int Accuracy
{
get {return accuracy;}
}
public int PP
{
get {return pp;}
}
}
```
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moves
{
public Move_Data Base { get; set; }
public int PP { get; set; }
public Moves(Move_Data pData)
{
Base = pData;
PP = pData.PP;
}
}
```
```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Pokemon", menuName = "Pokemon/Create new pokemon") ]
public class Pokemon_Data : ScriptableObject
{
//Pokedec Entries
[SerializeField] string name;
[TextArea]
[SerializeField] string description;
[SerializeField] Sprite frontSprite;
[SerializeField] Sprite backSprite;
[SerializeField] PokemonType type1;
[SerializeField] PokemonType type2;
//Base stats
[SerializeField] int maxHP;
[SerializeField] int attack;
[SerializeField] int defense;
[SerializeField] int spAttack;
[SerializeField] int spDefense;
[SerializeField] int speed;
[SerializeField] public List<NewMove> newMoves;
public string Name
{
get {return name;}
}
public string Description
{
get {return description;}
}
public Sprite FrontSprite
{
get {return frontSprite;}
}
public Sprite BackSprite
{
get {return backSprite;}
}
public PokemonType Type1
{
get {return type1;}
}
public PokemonType Type2
{
get {return type2;}
}
public int MaxHP
{
get {return maxHP;}
}
public int Attack
{
get {return attack;}
}
public int Defense
{
get {return defense;}
}
public int SpAttack
{
get {return spAttack;}
}
public int SpDefense
{
get {return spDefense;}
}
public int Speed
{
get {return speed;}
}
public List<NewMove> NewMoves
{
get {return newMoves; }
}
}
[System.Serializable]
public class NewMove
{
[SerializeField] Move_Data moveBase;
[SerializeField] int level;
public NewMove(Move_Data moveBase, int level)
{
this.moveBase = moveBase;
this.level = level;
}
public Move_Data Base
{
get {return moveBase;}
}
public int Level
{
get {return level;}
}
}
public enum PokemonType
{
None,
Normal,
Fire,
Water,
Electric,
Grass,
Ice,
Fighting,
Poision,
Ground,
Flying,
Pschic,
Bug,
Rock,
Ghost,
Dragon,
Steel,
Fairy,
}
```
``
您不能将
Moves
的类型添加到 NewMove
的列表中,因为它们是不同的类型,彼此没有关系。
在你的
Pokemon
构造函数中,替换
Moves.Add(new Moves(move.Base));
与
Moves.Add(new NewMove(move.Base, /*level*/));