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