I’m guessing, because it’s still a bit vague… I like the specific lines marked…
Are you saying that the line
GetComponent<PlayerConversant>().StartDialoge(script);
is yielding the null reference?
If that’s the case, is this script on the PlayerConversant or on a UI?
The PlayerConversant is generally on the player, meaning that you’ll need a reference to the player, GetComponent will only look on the same GameObject it’s called from without a reference…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Tree.Dialogue
{
public class DreamersConvert : MonoBehaviour
{
[SerializeField] Dialogue script = null;
[SerializeField] bool isPlayer = false;
PlayerConversant playerConversant;
void Awake()
{
playerConversant = GameObject.FindWithTag("Player").GetComponent<PlayerConversant>();
}
void Update()
{
PlayerTalking();
}
#region Triggers
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
isPlayer = true;
Debug.Log("Hello Player");
}
}
void OnTriggerExit2D(Collider2D other)
{
if(other.tag == "Player")
{
isPlayer = false;
Debug.Log("Goodbye Player");
}
}
#endregion
void PlayerTalking()
{
if(script == null)
{
return;
}
if (Input.GetButtonDown("Interactive") && isPlayer)
{
Debug.Log("We got it Tim.");
playerConversant.StartDialoge(script);
}
return;
}
}
}