【发布时间】:2018-11-12 11:20:06
【问题描述】:
if 语句都没有运行,我该怎么办? 所有公共变量都已赋值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OpeningCutscene : MonoBehaviour {
public int scroll;
public Text talk;
public GameObject textS;
public GameObject player;
public int banana = 0;
public int stuff = 1;
public GameObject smartHELP;
public GameObject smartRun;
// Use this for initialization
void Start () {
player.SetActive(false);
this.gameObject.SetActive(false);
smartRun.SetActive(false);
this.gameObject.transform.position = new Vector3(transform.position.x, transform.position.y - 0.9f, transform.position.z);
textS.SetActive(true);
}
// Update is called once per frame
void Update()
{
if (stuff == 1) {
if (scroll < 300) {
talk.color = Color.red;
talk.text = "Hello?";
} else if (scroll > 300 && scroll < 600) {
talk.text = "WAKE UP!";
} else {
talk.text = "";
stuff += 1;
}
scroll += 1;
Debug.Log("hi...");
}
if (stuff == 2)
{
if (banana != 90)
{
transform.Rotate(new Vector3(0.0f, 0.0f, -1));
this.gameObject.transform.position = new Vector3(transform.position.x, transform.position.y + 0.01f, transform.position.z);
banana += 1;
}
else if (banana == 90)
{
Debug.Log("Hi");
stuff = 3;
player.SetActive(true);
this.gameObject.SetActive(false);
smartRun.SetActive(true);
smartHELP.SetActive(false);
}
}
if (stuff == 3)
{
Debug.Log("hi");
smartRun.transform.position = new Vector3(smartRun.transform.position.x + 1.0f, smartRun.transform.position.y, smartRun.transform.position.z);
}
}
是的,这不是最紧凑的版本,但仍然是。
也请任何人链接到我可以用来学习 Unity C#(如 codeacademy)并且必须是免费的任何网站。
【问题讨论】:
-
是什么让您相信
if语句没有运行? -
你调试过这个,看看
stuff是什么?我猜它是零。 -
顺便说一句,
stuff是一个可怕的变量名! -
场景中对应的 GaneObject 是否处于活动状态且组件是否启用?
-
除了 .. 每次只检查一个变量的不同值时使用
switch
标签: c# if-statement unity3d