【问题标题】:OnDestroy not working properly UNITY 2DOnDestroy 无法正常工作 UNITY 2D
【发布时间】:2015-08-23 09:49:43
【问题描述】:

我目前在使用 OnDestroy 函数时遇到问题。我有 3 个类,PickUp、AddGold 和 Player,其中 PickUp 和 AddGold 是同一个预制件上的组件。

当我的角色与宝物发生碰撞时,PickUp 脚本会破坏它。然后 AddGold 应该在 Player 类中启动一个函数。

接机:

 void OnTriggerEnter2D(Collider2D other){
     if (other.gameObject.tag=="Player") {
         Destroy (this.gameObject);
     }

加金:

 public Player playerScript;
 public int gold;

 void onDestroy(){
     playerScript.addGold (gold);
 }

而且Player里面有这个功能

public void addGold(int gold){

     goldAmount += gold;
 }

为什么这不起作用?

【问题讨论】:

    标签: class unity3d 2d ondestroy


    【解决方案1】:

    方法被调用

    void OnDestroy()
    

    使用 O 而不是 o

    【讨论】:

      猜你喜欢
      • 2022-11-01
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多