@endybird

Проблема в юнити, как исправить?

Написал код, выдаёт ошибку Assets/pers/camera.cs(24,3): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement . Как исправить?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camera : 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.z);
		} else {
			transform.position = new Vector3 (Player.position.x + offset.x, Player.position.y + offset.y, transform.position.z);
		}
	}


	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;
		}
	}

}


P.S. Код для камеры
  • Вопрос задан
  • 152 просмотра
Решения вопроса 1
@ReWire_92
lastX - Mathf.RoundToInt (Player.position.x);
замени на
lastX = lastX - Mathf.RoundToInt (Player.position.x);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы