The problem is in the unit, how to fix it?
-
Wrote the code, gives an error Assets / pers / camera.cs (24,3): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement. How to fix it?
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. Camera CodeUnity Game Engine Anonymous, Jun 14, 2019 -
lastX - Mathf.RoundToInt (Player.position.x);
replace with
lastX = lastX - Mathf.RoundToInt (Player.position.x);
Sienna Blackwell
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!