0
私は、シーンの特定の部分を上に移動させたいときにtrueに設定するboolean変数を持っています。問題は、同じフレームの間にtrueに設定するたびにfalseにリセットされているようです。私はブールをプロパティにして、setメソッドでブレークポイントを設定し、パラメータとして "true"を指定して呼び出すだけです。Unity C#ブールがfalseにリセットされる
私が間違っていることがあるのでしょうか、Unityが奇妙なことをしていますか?
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は、MonoBehaviour派生クラス内のプロパティです。
EDIT2:全体のコード
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)'は、プロパティ 'SceneMoveUp'が真であるかどうかをチェックしているだけです。 if(SceneMoveUp)と同じです。私たちはポイントを見落としています。実際には 'SceneMoveUp'の値を設定していましたか? –
ViewStateを使って値を無効にしてください。 – Techidiot
十分に公正です。私は持っていた: 'if(SceneMoveUp)' 前に、しかし、私はパラノイドになって、== trueを追加するだけで安全になりました。 –