CameraController de clase pública: MonoBehaviour
{
// Referencia al transform del jugador
Transformar jugador;
// Distancias y velocidades de movimiento de la cámara
flotador público yDistance = 6f;
flotador público yMovement = 12f;
flotador público xDistance = 11f;
flotador público xMovement = 22f;
// Posiciones de la cámara
cámara pública Vector3Origin;
cámara pública Vector3Destino;
// Tiempo de movimiento de la cámara y estado de movimiento
movimiento del flotador públicoTiempo = 0,5f;
public bool se está moviendo;
inicio vacío()
{
// Buscar el objeto PlayerController en la escena y obtener su transform
Jugador = FindObjectOfType().transferencias;
}
Actualización nula()
{
// Verificar si la cámara está en movimiento
si (se está moviendo)
{
// Verificar la distancia vertical entre la cámara y el jugador
if(Player.position.y - Transform.position.y >= yDistance)
{
destinodecámara += nuevo Vector3(0, yMovement, 0);
StartCoroutine(MoveCamera());
}
else if((Transform.position.y - Player.position.y) >= yDistance)
{
destinodecámara -= nuevo Vector3(0, yMovement, 0);
StartCoroutine(MoveCamera());
}
// Verificar la distancia horizontal entre la cámara y el jugador
else if(Player.position.x - transform.Player.x >= xDistance)
{
destinodecámara += nuevo Vector3(xMovimiento, 0, 0);
StartCoroutine(MoveCamera());
}
else if(transform.Player.x - Player.position.x >= xDistance)
{
destinodecámara -= nuevo Vector3(xMovement, 0, 0);
StartCoroutine(MoveCamera());
}
// Rutina de movimiento de la cámara
IEnumerador MoveCamera()
{
se está moviendo = verdadero;
var currentPos = transformar.posición;
var t = 0f;
mientras (t<1)
{
t += Hora.deltaTiempo/movimientoTiempo;
// Interpolar entre la posición actual y la posición de destino de la cámara
transform.position = Vector3.Lerp(currentPos, cameraDestination, t);
// Mantener la posición en el eje Z constante
transformar.posición = nuevo Vector3(transformar.posición.x, transformar.posición.y, currentPos.z);
rendimiento retorno nulo;
}
se está moviendo = falso;
}
}
}
}[/código]
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see
links to documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?