Код юнити выдаёт ошибку, ни пойму в чём ошибка
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour
{
public float dumping = 1.5f
public Vector2 offset = new Vector2(2f. 1f)
public bool isLeft;
private Transform player;
private int lastX;
void Start()
{
offset = new Vector2(Mathf.Abs(offset.x), offset.y);
FindPlayer(isLeft);
}
public void FindPlayer(bool playerIsLeft)
{
player = GameObject.FindGameObjectWithTag("Player").Transform;
lastX = Mathf.RoundToInt(player.position.x);
if(playerIsLeft)
{
transform.position = new Vector3(player.position.x - offset.x, player.position.y + offset.y, transform.position);
}
else
{
transform.position = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position);
}
}
if(player)
{
int currentX=Mathf.RoundToInt(player.position.x);
if (currentX > lastX) isLeft=false;
else (currentX < lastX) isLeft=true;
lastX = Mathf.RoundToInt(player.position.x);
Vector3 target;
if (IsLeft)
{
target = new Vector3(player.position.x - offset.x, player.position.y - offset.y, transform.position);
}
else
{
target = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position);
}
Vector3 currentPosition = Vector3.Lerp(transform.position, target, dumping * Time.deltaTime);
transform.position = currentPosition;
}
}
По дате
По рейтингу
Пропущена точка с запятой после объявления переменных dumping и offset.
offset должен использовать запятую вместо точки в конструкторе Vector2.
Метод FindPlayer должен использовать transform вместо Transform.
Условие для проверки player и соответствующий код должны быть внутри метода Update.
Условие else использует синтаксис, который приведет к ошибке.
IsLeft должно быть isLeft.
transform.position должно учитывать координату z.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour
{
public float dumping = 1.5f;
public Vector2 offset = new Vector2(2f, 1f);
public bool isLeft;
private Transform player;
private int lastX;
void Start()
{
offset = new Vector2(Mathf.Abs(offset.x), offset.y);
FindPlayer(isLeft);
}
void Update()
{
if (player)
{
int currentX = Mathf.RoundToInt(player.position.x);
if (currentX > lastX) isLeft = false;
else if (currentX < lastX) isLeft = true;
lastX = Mathf.RoundToInt(player.position.x);
Vector3 target;
if (isLeft)
{
target = new Vector3(player.position.x - offset.x, player.position.y + offset.y, transform.position.z);
}
else
{
target = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position.z);
}
Vector3 currentPosition = Vector3.Lerp(transform.position, target, dumping * Time.deltaTime);
transform.position = currentPosition;
}
}
public void FindPlayer(bool playerIsLeft)
{
player = GameObject.FindGameObjectWithTag("Player").transform;
lastX = Mathf.RoundToInt(player.position.x);
if (playerIsLeft)
{
transform.position = new Vector3(player.position.x - offset.x, player.position.y + offset.y, transform.position.z);
}
else
{
transform.position = new Vector3(player.position.x + offset.x, player.position.y + offset.y, transform.position.z);
}
}
}