-
-
Save Hironyi/68814c3a1aed53cc02f2bb8358f02740 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
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