C# 调试字符串在一个函数中为空,但在另一个函数中填充
我要么开始做的时间太长(很有可能),要么某个特定的地产发生了一些奇怪的事情。当我从PlayerController脚本调试属性C# 调试字符串在一个函数中为空,但在另一个函数中填充,c#,unity3d,properties,C#,Unity3d,Properties,我要么开始做的时间太长(很有可能),要么某个特定的地产发生了一些奇怪的事情。当我从PlayerController脚本调试属性\u animalType时debug.Log(“动物类型是:”+\u animalType)它以空字符串的形式返回,但当我从CanvasControllerdebug.Log(player.GetComponent().AnimalType)调试它时它显示字符串填充了正确的数据。有人能看到这里发生了什么吗?谢谢大家! “CanvasController.cs”
\u animalType
时debug.Log(“动物类型是:”+\u animalType)代码>它以空字符串的形式返回,但当我从CanvasControllerdebug.Log(player.GetComponent().AnimalType)调试它时代码>它显示字符串填充了正确的数据。有人能看到这里发生了什么吗?谢谢大家!
“CanvasController.cs”
public void PrepareAnimalData()
{
StartCoroutine(DoPrepareAnimalData());
Debug.Log("Send To Forest Button Pressed.");
}
IEnumerator DoPrepareAnimalData()
{
yield return new WaitForEndOfFrame();
RenderTexture tmp = RenderTexture.active;
RenderTexture.active = BackLayerController.RenderTexture;
TmpTexture2D.ReadPixels(new Rect(0, 0, RenderTextureSize.x, RenderTextureSize.y), 0, 0, false);
player = GameObject.FindGameObjectWithTag("Player");
PlayerController.animalTex = TmpTexture2D; // set PlayerController animalTex to TmpTexture2D
player.GetComponent<PlayerController>().TexToBytes(); // run function from PlayerController
player.GetComponent<PlayerController>().AnimalType = PageConfig.UniqueId; // set animalType in PlayerController
Debug.Log(PageConfig.UniqueId);
Debug.Log(player.GetComponent<PlayerController>().AnimalType);
}}
您调用了它(显示它输出信息)
player.GetComponent().TexToBytes()代码>
在你设定之前
player.GetComponent<PlayerController>().AnimalType = PageConfig.UniqueId; // set animalType in PlayerController
player.GetComponent().AnimalType=PageConfig.UniqueId;//在PlayerController中设置animalType
您调用了它(显示它输出信息)
player.GetComponent().TexToBytes()代码>
在你设定之前
player.GetComponent<PlayerController>().AnimalType = PageConfig.UniqueId; // set animalType in PlayerController
player.GetComponent().AnimalType=PageConfig.UniqueId;//在PlayerController中设置animalType
当调用TexToBytes
时,它会在内部调用DebugAnimalData
日志数据。此时,\u animalType
仍被初始化为null
。但是,在此之后,您的下一个语句将通过Setter设置\u animalType
,因此,下一个调试日志将开始记录值当调用TexToBytes
时,它将在内部调用DebugAnimalData
日志数据。此时,\u animalType
仍被初始化为null
。但是,在此之后,您的下一个语句是通过Setter设置\u animalType
,因此,下一个调试日志开始记录该值帮个忙并了解..我确实知道自动属性。当我调试完这些属性后,它们将被配置为仅设置有一个你无法读取的属性有什么意义?这很公平,但是将这些属性更改为自动属性并不能解决实际问题,对吗?帮你自己一个忙,了解一下..我确实知道自动属性。当我调试完这些属性后,它们将被配置为只设置一个属性有什么意义?这很公平,但是将这些属性更改为自动属性并不能解决实际问题,对吗?