Created
March 25, 2014 16:30
-
-
Save takashicompany/9765700 to your computer and use it in GitHub Desktop.
Unityで継承を用いて共通化を図る例。おそらくこれが良い方法。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通化のクラス | |
public class MyButton : MonoBehaviour | |
{ | |
void Press (); | |
} | |
// MyButtonを実装したクラス | |
public class StartButton : MyButton | |
{ | |
public void Press () | |
{ | |
// Press Function... | |
} | |
} | |
// MyButtonを実装したクラス | |
public class SelectButton : MyButton | |
{ | |
public void Press () | |
{ | |
// Press Function... | |
} | |
} | |
public class View : MonoBahaviour | |
{ | |
public MyButton startButton; | |
public MyButton selectButton; | |
void Awake () | |
{ | |
// MyButtonクラスはMonoBehaviourを継承しているため、 | |
// gameObjectを参照することができる。 | |
startButton.gameObject.SetActive(false); | |
selectButton.gameObject.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment