Answer the question
In order to leave comments, you need to log in
The problem is in the unit, how to fix it?
Wrote code, gives 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?
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;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question