敵の攻撃を作る②(プレーヤーを感知して向きを変える)

レーダー機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Radar : MonoBehaviour
{
[SerializeField]
private Transform target;
// 「OnTriggerStay」はトリガーが他のコライダーに触れている間中実行されるメソッド(ポイント)
private void OnTriggerStay(Collider other)
{
// もしも他のオブジェクトに「Player」というTag(タグ)が付いていたならば(条件)
if (other.CompareTag("Player"))
{
// 「root」を使うと「親(最上位の親)」の情報を取得することができる(ポイント)
// LookAt()メソッドは指定した方向にオブジェクトの向きを回転させることができる(ポイント)
transform.root.LookAt(target);
}
}
}









【2020版】BattleTank(基礎/全35回)
他のコースを見る
レーダー機能の実装
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Radar : MonoBehaviour
{
[SerializeField]
private Transform target;
// 「OnTriggerStay」はトリガーが他のコライダーに触れている間中実行されるメソッド(ポイント)
private void OnTriggerStay(Collider other)
{
// もしも他のオブジェクトに「Player」というTag(タグ)が付いていたならば(条件)
if (other.CompareTag("Player"))
{
// 「root」を使うと「親(最上位の親)」の情報を取得することができる(ポイント)
// LookAt()メソッドは指定した方向にオブジェクトの向きを回転させることができる(ポイント)
transform.root.LookAt(target);
}
}
}









敵の攻撃を作る②(プレーヤーを感知して向きを変える)