Skip to content

Instantly share code, notes, and snippets.

@takashicompany
Created March 25, 2014 16:30
Show Gist options
  • Save takashicompany/9765700 to your computer and use it in GitHub Desktop.
Save takashicompany/9765700 to your computer and use it in GitHub Desktop.
Unityで継承を用いて共通化を図る例。おそらくこれが良い方法。
// 共通化のクラス
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