Search code examples
unity-game-enginevirtual-realitydaydream

Unity & Daydream - Having Dialogs with other Characters


I am building a Daydream app via Unity, have a basic first person demo working but I have not developed on Unity before. Looking to add characters to the app and have dialogs with them. I am considering two ways:

  1. When I go near to a character a dialog box would come up next to that character and say "Hello".
  2. When I point to a character with the pointer it would say "start conversation"

After either case I would have multiple options to choose from eg. "Where is X" or "what is your name" etc then depending on my selection the character would respond with something else and so on. I couldn't see something that would solve this in standard assets. Are there any best practices, templates around this? If not any ideas / directions?

Unity 2017.3.1f1
GVR SDK: v1.130.1
Android Studio 3.0.1
Java jdk1.8.0_162.jdk
Pixel 2 phone
MacBook High Sierra


Solution

  • It is pretty easy just follow these steps;

    Add a collider to the character, and put a 3d text on where you want "Hello" to pop up and add a script like this;

    public text HelloText = null;
    
    void OnCollisionEnter(Collision collision)
    {
       HelloText.text.enabled = true;
    }//Search more on google ; Unity 3d text.
    

    Create a cube scale it as you desire and put a text in it like "Start Conversation". Add a collider to the cube and a script like this;

      void OnMouseDown()
        {
            //Create dialog boxes LIKE THIS.
        }
    

    This is not the perfect way to do it. If you are new this might be the best option for you.

    You can create a prefab which made of cube and a text. Then you can set their values thru script.

    EDIT:

    Create an empty game object and attach this script to it. Then put 3rdPersonController gameobject to empty gameobject slot in empty game object's script

    Example:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class AScriptName: MonoBehaviour {
    
     public GameObject PlayerController = null;
     TextMesh DialogBox = null;
    
    void Start()
    {
    
    //Note: Attach your 3d text to your 3rdPersonController in the editor..
    
    DialogBox = PlayerController.GetComponentInChildren(typeof(TextMesh)) as TextMesh;
    
    DialogBox.text = "Start Conversation";
    
    //or you can pass a string value;
    //Example string text = "Start Conversation"; DialogBox.text = text;
    
    }
    
    }