0

編集

私の質問は異なります (私は思う..) 最後の画像では、GameObject を Communication Message と Communication Message に設定できるためです。しかし、再生すると、すぐになし (テキスト) となし (ボタン) にリセットされます。なぜこれが起こるのか、これを解決する方法がわかりません!


この質問が広く取り上げられていることは承知していますが、それでも解決できません。誰かが私に解決策を持っていることを願っています。

私が持っているもの

Unity のアセットであるBehavior Designerを使用しています。ビヘイビア ツリーを作成していますが、ビヘイビア ツリー参照を使用すると問題が発生しました。

まず、ビヘイビア ツリーを次のようにしました。

ビヘイビア ツリー - 検索ドア

玄関先を捜索します。見つかった場合は、それに向かって移動し、ゲームをプレイしている人間と通信します。

これは以前は機能していましたが、今回はこのビヘイビア ツリーを次のようにビヘイビア ツリー リファレンスに入れました。

ビヘイビア ツリー リファレンス

参照をダブルクリックすると、最初の画像が表示されます。しかし、それがうまくいかないのはこれです:

人間の指示

問題

これは、最初の図のヒューマン インストラクション ノードです。通信メッセージ、通信ボタンは搭載しません。対応するボタンをロードすると、シナリオの再生時にすぐにリセットされます。これは Behavior Tree Reference にこのビヘイビアーをロードしたときに発生し、元のツリー セルフからこれを再生したときには問題は発生しませんでした。

NullReferenceException: Object reference not set to an instance of an object
HumanInstructions.CommunicationElements (Boolean activeOrNot) (at Assets/HumanInstructions.cs:54)
HumanInstructions.OnAwake () (at Assets/HumanInstructions.cs:19)
BehaviorDesigner.Runtime.BehaviorManager.EnableBehavior (BehaviorDesigner.Runtime.Behavior behavior)
BehaviorDesigner.Runtime.Behavior.EnableBehavior ()
BehaviorDesigner.Runtime.Behavior.Start ()

これを引き起こす可能性のあるアイデアと、これを解決する方法はありますか?

HumanInstructions のコード

using UnityEngine;
using UnityEngine.UI;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using UnityStandardAssets.Characters.FirstPerson;

public class HumanInstructions : Action
{
    public string humanInstructionsText; // The string in inspector that shows up on-screen for the human operator to communicate with UGV.
    public string messageToConsole; // Print this message to console when the action is performed SUCCESSFUL.
    public string textOnButton; // See inspector in Behavior Designer. Is used as text on button.
    public Text CommunicationMessage;
    public Button CommunicationButton;
    bool boolClicked; // Is false; when the button is clicked, it will turn TRUE, calling the IF function, returning Taskstatus SUCCESS.


    public override void OnAwake ()
    {
        CommunicationElements (false);
    }

    public override void OnStart ()
    {
        boolClicked = false;
        CommunicationElements (false);
        CommunicationButton.onClick.AddListener (ButtonClicked);
    }

    public override TaskStatus OnUpdate ()
    {
        CommunicationMessage.text = humanInstructionsText;
        CommunicationButton.GetComponentInChildren<Text> ().text = textOnButton;
        CommunicationElements (true); // The communication elements are VISIBLE on screen.
        TriggerStatusCameraView (false);
        if (boolClicked == true) { // this IF function is active when the button is clicked. See ButtonClicked () function.
            CommunicationElements (false); // Removes the communication elements from screen.
            TriggerStatusCameraView (true);
            return TaskStatus.Success;
        } else {
            return TaskStatus.Running;
        }
    }

    // The following function is called when the CommunicationButton is clicked on screen.
    void ButtonClicked ()
    {
        boolClicked = true; // Changes the value to true, so it will trigger the IF function in OnUpdate ();
        Debug.Log (messageToConsole); // Sends this message to the console.
    }

    // The following function can be called upon and turn all UI elements (such as text, buttons or images) ACTIVE or not.
    void CommunicationElements (bool activeOrNot)
    {
        CommunicationButton.gameObject.SetActive (activeOrNot);
        CommunicationMessage.gameObject.SetActive (activeOrNot);
    }

    // The following code will DISABLE camera control if the communication screen is active for the human operator
    void TriggerStatusCameraView(bool activeOrNot)
    {
        GameObject.Find ("FPSController").GetComponent<RigidbodyFirstPersonController_custom> ().enabled = activeOrNot;
    }
}
4

1 に答える 1

2

解決策は簡単でした。ご検討いただきありがとうございます。

Text CommunicationMessage = GameObject.Find("CrazyMsg").GetComponent<Text>();
Button CommunicationButton = GameObject.Find("MissionButton").GetComponent<Button>();
于 2016-11-18T13:07:00.487 に答える