Skip to content

Instantly share code, notes, and snippets.

@Hironyi
Created June 16, 2021 16:02
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 Hironyi/68814c3a1aed53cc02f2bb8358f02740 to your computer and use it in GitHub Desktop.
Save Hironyi/68814c3a1aed53cc02f2bb8358f02740 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Attacker : MonoBehaviour
{
//インターフェイスで武器を持っておく。
IWeapon weapon;
public void Start()
{
//GetComponentよりも綺麗に書けてオススメ。
gameObject.TryGetComponent<IWeapon>(out weapon);
//攻撃メソッドの呼び出し
Attack();
}
public void Attack()
{
//Weaponの攻撃を呼び出す。
weapon.Attack();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment