I have a boolean variable which I set to true when I want certain parts of my scene to move up. The problem is, it seems to be resetting to false every time I set it to true, during the same frame. I've made the bool into a property and set a breakpoint in the set method and it only ever gets called with "true" as a parameter.
Is there something I'm doing wrong, or is Unity doing some weird stuff behind?
private bool SceneMoveUp
{
get
{
return _sceneMoveUp;
}
set
{
_sceneMoveUp = value;
}
}
void Update () {
if (SceneMoveUp == true) {
transform.position = Vector3.MoveTowards(transform.position, SceneDestination, speed * Time.deltaTime);
}
}
EDIT: SceneMoveUp is a property inside a MonoBehaviour-derived class.
EDIT2: entire code
using UnityEngine;
using System.Collections;
public class PseudoScene : MonoBehaviour {
public Vector3 ZoomOutPosition;
public GameObject[] Letters;
public Vector3[] CameraPositions;
public PseudoSceneManager _manager;
public float speed;
private float DepartureTime;
private Vector3 TextureOffset;
private int LetterCount, CurrentIndex = 0;
private bool ZoomingOut = false;
private bool _sceneMoveUp;
private bool SceneMoveUp{ get
{
return _sceneMoveUp;
}
set
{
_sceneMoveUp = value;
}
}
static public bool MovingCamera = false;
private Vector3 BackgroundFinalScale;
private Vector3 SceneDestination;
[SerializeField]private Quaternion FinalRotation;
void Start () {
LetterCount = Letters.Length;
SceneMoveUp = false;
if (LetterCount == 1) {
CameraPositions = new Vector3[1];
CameraPositions[0] = transform.position;
CameraPositions[0].z = -10;
}
ChangeLetter();
}
public void LetterFilled () {
CurrentIndex++;
if (CurrentIndex < LetterCount) {
ChangeLetter();
} else {
if (LetterCount > 1) {
ZoomOut();
} else {
MoveScene();
}
Invoke("FinishScene", 3f);
}
}
void Update () {
if (ZoomingOut) {
Camera.main.transform.position = Vector3.Lerp(transform.position, ZoomOutPosition, 1f);
Camera.main.orthographicSize = Mathf.Lerp(Camera.main.orthographicSize, 13, 0.1f);
}
if (MovingCamera) {
Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, CameraPositions[CurrentIndex], speed * Time.deltaTime);
if (Camera.main.transform.position == CameraPositions[CurrentIndex]) {
MovingCamera = false;
Checkpoint.DeactivateAllCheckpoints(true);
if (LetterCount > 1 && CurrentIndex >= 1) {
Checkpoint.DeactivateAllCheckpoints(true);
}
}
}
if (SceneMoveUp == true) {
transform.position = Vector3.MoveTowards(transform.position, SceneDestination, speed * Time.deltaTime);
}
}
void MoveScene () {
DepartureTime = Time.time;
SceneMoveUp = true;
Debug.logger.Log("set SceneMoveUp to ", SceneMoveUp.ToString());
SceneDestination = transform.position;
SceneDestination.y += 10;
}
public void FinishScene () {
_manager.SceneFinished();
}
//5.75
void ChangeLetter () {
Checkpoint.DeactivateAllCheckpoints(false);
MovingCamera = true;
}
void ZoomOut () {
ZoomingOut = true;
}
}
if(SceneMoveUp == true)
you're just checking if the PropertySceneMoveUp
is true. It's the same asif(SceneMoveUp)
. We're missing the point, were you actually setting the value ofSceneMoveUp
– Christoph K