Friday, December 16, 2016

Making Dialog Appear in Unity, Game Dev

I followed this tutorial for melee combat: https://www.youtube.com/watch?v=HzTceINFowY Then just adjusted it for dialog. Basically using the same code to initiate dialoge instead of damage. Adjusting the MaxDistance to something farther away. And changing Fire1, to Fire2. Script for reciever:
function thingCast() {

Debug.Log("Confrontation");
canvasObject.SetActive(true);
}
Script for Sender:
        if(Input.GetButtonDown("Fire2"))
        {


                var hitt : RaycastHit;

                Debug.Log("Fire2");
                if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hitt))
                {
                Distance = hitt.distance;
                if(Distance > MaxDistance){
                hitt.transform.SendMessage("thingCast", SendMessageOptions.DontRequireReceiver);
                }
                }
        }

Assign the actual Canvas object to canvasObject in the inspector.

No comments: