[Unity]~SIER에서 게임업계로~4-2차 적
4343 단어 Unity
기본 기능
• 플레이어 추적
• 일정 거리 내에서만 추적
・ 플레이어의 공격을 받고 사라짐
배운 곳
NavMeshAgent를 사용하여 사용자 추적
Ememy.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : BaseBehaviour {
public GameObject target;
NavMeshAgent agent;
private Vector3 pPos;
private Vector3 ePos;
// Use this for initialization
void Start () {
agent = GetComponent<NavMeshAgent>();
agent.speed = 0;
}
// Update is called once per frame
void Update () {
// プレイヤーとの距離を算出
pPos = target.transform.position;
ePos = transform.position;
var dist = Vector3.Distance(pPos, ePos);
// 一定距離に近づいたら動き出す
if (dist < 10)
{
agent.speed = 2;
}
// 敵オブジェクトの目的地を指定
agent.destination = pPos;
}
private void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Fire")
{
Destroy(this.gameObject);
}
}
}
Reference
이 문제에 관하여([Unity]~SIER에서 게임업계로~4-2차 적), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/straycatz/items/af859da51483de3866dd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)