Skip to content

Instantly share code, notes, and snippets.

@kazumalab
Last active August 22, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazumalab/26a7ca04eacdbc03c43f45b4b38c5a02 to your computer and use it in GitHub Desktop.
Save kazumalab/26a7ca04eacdbc03c43f45b4b38c5a02 to your computer and use it in GitHub Desktop.
public class CharactorMainController : MonoBehaviour { // スーパークラス
public Image myself_image;
public Image map_image;
// Move 関数をここに書いてもいい
public virtual void MapCharactorMotion (Image image) {
// Player, Enemyの向いている方向に合わせてimageも回転
image.transform.rotation = Quaternion.Euler (0, 0, -transform.rotation.y * 180);
}
public virtual void MapMotion () { // Mapの画像を移動させる(Playerが移動しているようにみせる)
map_image.transform.localPosition = new Vector2 (-transform.position.x * 10, -transform.position.z * 10);
}
}
public class Enemy : CharactorMainController { // サブクラス
// Inspectorでmyself_imageにEnemy_imageを入れておく
private void Update () {
MapCharactorMotion (myself_image);
}
public override void MapCharactorMotion (Image image){
base.MapCharactorMotion (image);
// localpositionにするのはmapの上を動くから
image.transform.localPosition = new Vector2 (this.transform.position.x * 10, this.transform.position.z * 10);
}
// enemyはmap上で動くのでMapMotion関数をオーバーライドする必要はない
}
public class Player : CharactorMainController { // サブクラス
// Inspectorでmyself_imageにPlayer_imageを入れておく
private void Update () {
MapCharactorMotion (myself_image);
MapMotion ();
}
public override void MapCharactorMotion (Image image) {
base.MapCharactorMotion (image);
}
public override void MapMotion () {
base.MapMotion();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment