Last active
August 22, 2016 19:49
-
-
Save kazumalab/26a7ca04eacdbc03c43f45b4b38c5a02 to your computer and use it in GitHub Desktop.
This file contains 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 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); | |
} | |
} |
This file contains 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 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関数をオーバーライドする必要はない | |
} |
This file contains 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 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