0
我如何绕过任何派生类的问题和两次写代码?来自派生类的抽象过程函数和变量
我曾尝试以下:
Type t = GetType(obj);
(obj as t).health
这样一来,视觉Sudio saysme health is not member of... blah
这里是我的代码:从GameObject
class anyclass
{
void checkhealth(gameobject obj) // QUESTION:
{
if (obj as player).health = 0 //
kill(obj) //
if (obj as enemy).health = 0 //
kill(obj) //
// gameobjects-class
abstract gameobject
{
Vector2 Position
void update()
etc...
class meteor : gameobject
{
float rotation
etc...
class player : gameobject
{
int health, attackpower
etc...
class enemy: gameobject
{
int health, attackpower
etc...
外部类访问数据
有什么建议吗?谢谢!
听起来不错!将检查!谢谢!!!!!! – 2014-08-28 07:13:59