static void Main(string[] args) { var wk = new WarmKiller(); //只有当IKill对象来引用WarmKiller的实例时,才能调用Kill方法 IKill ki = wk; ki.Kill(); }
// Detect type of object on Collision private void OnTriggerEnter(Collider other) { if (GameSystem.gameState == GameStates.Playing) { Collectibles collectible = other.GetComponent <Collectibles>(); IKill killableObject = other.GetComponent <IKill>(); if (collectible != null) { GameSystem.instance.CollectCoins(collectible.value); collectible.Interactions(); } if (killableObject != null) { killableObject.Kill(); GameSystem.instance.EndGame(); } } }