
前の記事で敵の体のコライダーが付けたボーンにスクリプトを付けて、部位ごとに敵が受けるダメージを変えられるようにします。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBodyScript : MonoBehaviour
{
AgentAttackTest sc_agent;
[SerializeField][Range(0f,1f)] float damage = 0.1f;
private void Start()
{
sc_agent = transform.root.GetComponent<AgentAttackTest>();
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "Weapon" && collision.collider.gameObject != sc_agent.collidedObject)
{
sc_agent.SetHP(-damage);
sc_agent.collidedObject = collision.collider.gameObject;
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Weapon")
{
sc_agent.SetHP(-damage);
sc_agent.collidedObject = other.gameObject;
}
}
}
これは、敵のルートのスクリプトのHPを減らすメソッドの引数に渡す値をインスペクタから設定できるようにしただけです。

