AP
Size: a a a
AP
👨n
private void Update()
{
transform.Translate(Vector3.forward * speed * direction * Time.deltaTime);
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
if (!GeometryUtility.TestPlanesAABB(planes, collider.bounds))
direction *= -1;
}
AN
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
if (!GeometryUtility.TestPlanesAABB(planes, collider.bounds) && !isOutOfBounds)
{
isOutOfBounds = true;
direction *= -1;
}
Только теперь вопрос, как её сбросить обратно. Ещё одну проверку в каждый Update втыкать что ли?AP
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
if (!GeometryUtility.TestPlanesAABB(planes, collider.bounds) && !isOutOfBounds)
{
isOutOfBounds = true;
direction *= -1;
}
Только теперь вопрос, как её сбросить обратно. Ещё одну проверку в каждый Update втыкать что ли?isOutOfBounds = false
AP
👨n
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
if (!GeometryUtility.TestPlanesAABB(planes, collider.bounds) && !isOutOfBounds)
{
isOutOfBounds = true;
direction *= -1;
}
Только теперь вопрос, как её сбросить обратно. Ещё одну проверку в каждый Update втыкать что ли?АТ
👨n
AN
isOutOfBounds = false
AP
AN
👨n
AN
👨n
transform.position.X <= N
где у тебя указана изначальная координата, без высчитывания лишних пересечений пока едет назад. Т.е.if(isOutOfBound){
if(transform.position.X <= N){
isOutOfBound = false;
direction *= -1;
}
}else{
Plane[] planes = ....
if(!Geomentry.....){
isOutOfBound = true;
direction *= -1;
}
}
M
AN
👨n
AN
IC
IC