我试图让一些对象和类进行交互。
我有两节课。代码类似。但是在class Building_main
之后,在Start()中初始化了对象后,我可以在函数中重用它,在class House_main
中我不能(对象为空)。class Building_main
是{{1}的子节点}。
我做错了什么?
头等舱:
class House_main
第二课:
public class Building_main : MonoBehaviour {
public string owner;
public string producedGoodName;
private Building_goods goods;
private House_main house;
void Start () {
goods = this.transform.Find("Building_goods").GetComponent<Building_goods>();
house = this.transform.parent.gameObject.GetComponent<House_main> ();
UpdateHouseInfo ();
}
void UpdateHouseInfo () {
// reusing objs (house, goods) no error
house.UpdateGoodInfo (goods.GetGoodByName("sword"), "sword");
}
答案 0 :(得分:0)
看起来我的子类( <div id="app">
<div class="wrapper">
<p>THIS IS MY CONTENT</p>
</div>
<footer>
This is the footer
</footer>
</div>
)Start()函数正在父类(// surely you don't want a copy?
for(auto&& Variant : variantContainer)
{
auto should_break = false;
// If the variant types match, set the value
std::visit([this, &should_break](auto&& arg)
{
// arg is one of the Ts... in the variant
this->doTheRightThing(arg);
if (shouldCauseBreak(arg))
should_break = true;
}, Variant);
if (should_break)
break;
}
)Start()函数之前执行。
因此我在调用class Building_main
时尚未分配class House_main
对象class House_main
,因为我使用goods
调用它来启动它()
function UpdateGoodInfo
不知道这个。