Skip to content

Instantly share code, notes, and snippets.

@gremito
Last active December 20, 2019 13:03
Show Gist options
  • Save gremito/21cf73336e5ec38ba12736415b1bc5b6 to your computer and use it in GitHub Desktop.
Save gremito/21cf73336e5ec38ba12736415b1bc5b6 to your computer and use it in GitHub Desktop.
Human.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseEnemy : MonoBehaviour
{
// 必要なパラメータ
// -> 体力ポイント : 1(初期値)
// -> 攻撃ポイント : 1(初期値)
// -> エフェクト
// -> 効果音
// -> 死亡フラグ(false = 生きてる, true = 死んでる)
// -> アニメーション(待機・移動・攻撃・ダメージ・死亡...etc)
// 移動処理
// 攻撃処理
// -> 攻撃アニメーションを再生
// ダメージ処理
// -> 体力ポイントをマイナスにする
// -> 体力ポイントが0になったら死亡状態(死亡フラグをtrue)にする
}
public class HumanEnemy : BaseEnemy
{
// Baseクラスを継承してインスタンスを作る
// 必要なパラメータ
// -> 体力ポイント : 10(初期値)
// -> 攻撃ポイントを付ける:5(初期化)
// -> エフェクト
// -> 効果音
// -> 死亡フラグ(false = 生きてる, true = 死んでる)
// -> アニメーション(待機・移動・攻撃・ダメージ・死亡...etc)
protected static int hashIsDamage = Animator.StringToHash ("isDamage");
[SerializeField, HideInInspector] protected Animator animator;
[SerializeField, HideInInspector] protected SpriteRenderer spriteRenderer;
[SerializeField, HideInInspector] protected Rigidbody2D rig2d;
[SerializeField]
private bool isDamage;
void Start()
{
animator = GetComponent<Animator> ();
spriteRenderer = GetComponent<SpriteRenderer> ();
rig2d = GetComponent<Rigidbody2D> ();
isDamage = false;
}
void Update() {
if(isDamage)
{
// アニメーションを再生する
animator.SetBool (hashIsDamage, isDamage);
}
}
// 移動処理
// -> Baseクラスの移動処理を使う(オーバーロードorオーバーライド)
// ->
// 攻撃処理
// -> Baseクラスの攻撃処理を使う(オーバーロードorオーバーライド)
// ->
// ダメージ処理
// -> Baseクラスのダメージ処理を使う(オーバーロードorオーバーライド)
// ->
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment