나는 이것을 가장 쉬운 방법으로 설명하려고 노력할 것입니다. 나는 적 플레이어를 위해 약간의 인공 지능을 만들고 있습니다. AI가 레이 캐스트가 플레이어에게 닿으면 AI가 뒤로 이동하기를 원하지만 심각한 문제가 있습니다. [코드 아래에 설명 할 것]Unity 업데이트 기능을 일시적으로 무시하는 방법 [C#]
코드;
using UnityEngine;
using System.Collections;
public class NewEnemyAI : MonoBehaviour
{
public GameObject enemy;
public Transform target;
public float movementSpeed = 2f;
private CharacterController enemyCharacterController;
private bool enemyHit;
private Vector3 startPos;
private Vector3 endPos;
private float distance = 7f;
private float lerpTime = 0.3f;
private float currentLerpTime = 0f;
private bool avoid;
private bool updateOn = true;
private bool hitPlayer = false;
// Use this for initialization
void Start()
{
avoid = false;
}
// Update is called once per frame
void Update()
{
//raycasting
if (Physics.Raycast(transform.position, transform.forward, 2))
{
startPos = enemy.transform.position;
endPos = enemy.transform.position + Vector3.back * distance;
avoid = true;
}
else
{
avoid = false;
}
if (avoid == true)
{
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
{
currentLerpTime = lerpTime;
}
float perc = currentLerpTime/lerpTime;
enemy.transform.position = Vector3.Lerp(startPos, endPos, perc);
avoid = false;
}
if (avoid == false)
{
currentLerpTime = 0;
transform.LookAt(target);
transform.Translate(Vector3.forward * Time.deltaTime * movementSpeed);
}
}
}
적의 레이 캐스트 플레이어 안타
는, 그에 해당하는 경우, 그것은 플레이어의 움직임을 다시 만드는 true로 부울을 설정합니다. 그러나 플레이어가 뒤로 움직이기 때문에 레이 캐스팅이 플레이어에게 더 이상 부딪치지 않으며 코드에서 코드로 점프하기 때문에이 전체 프로세스가 다시 시작되고 적의 고무줄이 생깁니다. 코드가 광선 캐스트 if 문을 무시하고 달리 말하지 않는 한 영구적으로 bool 피를 true로 설정하는 방법이 있습니까? 감사! [저는 C#에 비교적 익숙합니다. 제 코드를 너무 비판하지 마십시오.]
"쿨 다운"개념에 동의합니다. 그것은 불필요한 충돌 검사 및 올바른 상황에서 실패 할 수있는 다른 것들을 피할 수 있습니다. – Krythic