public class CustomizationUI : MonoBehaviour
{
private bool ifTGOn = false;
private bool ifTBOn = false;
......(some variable declaration)
int tg=0;
int bg=0;
int tb=0;
int bb=0;
string gender = "boy";
public async void loadTopMaterialCards()
{
if (gender == "boy"){
if (tb==0){
contentPanelTB.SetActive(true);
contentPanelBB.SetActive(false);
ifTBOn = true;
Debug.Log("I ammmmmmmmmmmm ifTBON"+ifTBOn);
for (int i=0; i<topBoyMaterials.Count; i++){
AsyncOperationHandle<GameObject> handle = Addressables.InstantiateAsync("MaterialCard");
await handle.Task;
GameObject matcard = handle.Result;
matcard.transform.SetParent(ViewPanelTB);
MaterialCard mcard = matcard.GetComponent<MaterialCard>();
mcard.image.sprite = topBoyImages[i];
mcard.material = topBoyImages[i].name;
}
tb++;
}else if (tb==1){
contentPanelTB.SetActive(true);
contentPanelBB.SetActive(false);
ifTBOn = true;
}
}
Debug.Log("I am TG and TB at the second time"+ifTGOn+ifTBOn);
}
public async void loadBottomMaterialCards()
{
Debug.Log("I am TG and TB at the third time"+ifTGOn+ifTBOn);
if (gender == "boy"){
if (bb==0){
contentPanelTB.SetActive(false);
contentPanelBB.SetActive(true);
ifTBOn = false;
for (int i=0; i<bottomBoyMaterials.Count; i++){
AsyncOperationHandle<GameObject> handle = Addressables.InstantiateAsync("MaterialCard");
await handle.Task;
GameObject matcard = handle.Result;
matcard.transform.SetParent(ViewPanelBB);
MaterialCard mcard = matcard.GetComponent<MaterialCard>();
mcard.image.sprite = bottomBoyImages[i];
mcard.material = bottomBoyImages[i].name;
}
bb++;
}else if (bb==1){
contentPanelTB.SetActive(false);
contentPanelBB.SetActive(true);
ifTBOn = false;
}
}
Debug.Log("I am TG and TB at the fourth time"+ifTGOn+ifTBOn);
}
public void changeMaterial(){
Debug.Log("HIIII iam panellll"+ifTBOn);
}
void Awake(){
instance = this;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}}在方法loadTopMaterialCard()中,我在按下按钮后(统一)将bool ifTBOn设置为true,loadTopMaterialCard内部的调试显示它已被设置为true,但是,在ifTBOn设置为true之后,我尝试在changeMaterial()中调试,但它显示为false。这是整个类的一部分,我不知道为什么bool在changeMaterial()类中调试它时总是错误的,如何修复它呢?
(我认为在我的代码中没有什么地方可以将bool编辑回false
发布于 2022-04-07 18:14:33
这里的问题很可能是,你的布尔人在一开始就没有被设定为真的。在多个方法中访问它应该没有问题。
我将逐步使用断点遍历这段代码,并确保您的if语句正在传递,并且代码将达到可以将布尔值设置为true的点。
如果是的话,那么代码中肯定还有其他地方,您要将它们设置为false。
除了这两件事之外,我们还需要看到访问它们的第二个方法和任何其他涉及字段的代码。
发布于 2022-04-08 13:35:37
对不起,如果我挑剔,但我强烈建议不要使用这样的变量名称。在我看来,这些都是误导、毫无意义和相当丑陋的。我希望你将来能找到更好的名字。
其中一部分是loadBottomMaterialCards方法,其中将ifTBOn设置为false。
我想这个方法是在你不知情的情况下执行的。尝试在那里设置一个断点,看看指令指针是否在那里。
祝你好运,记住名字<3
https://stackoverflow.com/questions/71786685
复制相似问题