0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unityのassetのfungusを使って会話シーンを作りたい

Posted at

使っているもの、環境

fungus
https://assetstore.unity.com/packages/templates/systems/fungus-34184
unity 2019.1.1f1

やろうとしていること

ストーリーモードを作ろうとしている。戦闘シーン→会話シーン->戦闘シーン...と繰り返したいがそれごとに会話シーンを作るのは面倒なので会話シーンを一つだけ作って再利用したい。ベストプラクティスはさておき手探りで実行できるようにした

どうやってやろうとしているか

会話用のシーンを作って、fungusのフローチャートを以下のように作って会話シーンに遷移したときに渡された情報からどの会話を開始させるかを判別する
image.png
実際はタイトルシーン->prologue->story1_1->ゲームシーン->...と遷移させたい
シーン間の情報を渡す方法は変数をstaticにして渡したりDontDestroyOnLoadを使ったりということができるらしいので、何かしらの方法で渡す。今回はGameSystemScriptというクラスを作成してDontDestoryOnLoadで消えないようにしてみた

public class GameSystemScript : MonoBehaviour
{
    public static int nextTalkScene = 1; 
    public int getNextTalkScene()
    {
        return nextTalkScene;
    }

    public void setNextTalkScene(int n)
    {
        nextTalkScene = n;
    }
  private void Awake()
  {
      // GameSystemはGameSystemScriptをアタッチしたgameObject
      DontDestroyOnLoad(GameSystem);
  }

タイトルシーンでGameSystemScriptのnextTalkSceneを設定して次のシーンに遷移させる

GameSystem.GetComponent<GameSystemScript>().setNextTalkScene(0);
SceneManager.LoadScene(nextScene);        
public class TalkSceneMain : MonoBehaviour
{
    public Fungus.Flowchart flowchart;

    GameSystemScript gameSystem;
    void Start()
    {
        gameSystem = FindObjectOfType<GameSystemScript>();
        int nextTalkScene = gameSystem.getNextTalkScene();
        switch (nextTalkScene)
        {
            case 0:
                flowchart.ExecuteBlock("prologue");
                break;
            case 1:
                flowchart.ExecuteBlock("story1_1");
                break;
            case 2:
                flowchart.ExecuteBlock("story1_2");
                break;
            case 3:
                flowchart.ExecuteBlock("story1_3");
                break;
        }
    }
...

これでタイトルシーンが終わったらTalkSceneに入ってfungusのprologueを実行できるようになった。
これを拡張すればTalkSceneが実行されるときに任意の会話が会話できるようになった

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?