DialogTrigger
Triggering Dialog with Collider2D interactions
DialogTrigger.cs (Important: see version 2 below)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This class provides a logic for the player to trigger dialog using a 2D collider
/// This script will be added to a gameObject with a collider2D with isTrigger true
///
/// THis script requires that the dialogManager instance which will execute the dialog
/// must be populated in the inspector panel
/// as well as the ConversationList scriptableObject that will be displayed when triggered
///
/// This can be used on multiple objects within a scene, where each instance will have it's own
/// conversation to be exectued.
/// </summary>
public class DialogTrigger : MonoBehaviour
{
public ConversationList convList; //populate in the inspector
public DialogManager dialogManager; //Populate in the Inspector
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
Debug.Log("Collided with DialogTrigger");
if (dialogManager != null) //populated in the inspector
{
dialogManager.TriggeredDialog(convList); //pass the convList as a parameter into the DialogManager
Debug.Log("Trigger dialog");
}
else
{
Debug.Log("Couldn't find dialogManager to trigger");
}
}
}
} //end class
DialogTrigger version2
Last updated