Once more having some trouble referencing actors properly. I'm creating a situation in which the player has to assign NPC's to the right seats via a click and drag mini game.
I'm tyring to figure out how to get it so that the script knows when the dragged object is being placed in the right spot. I have given all the NPC items being dragged actor components, but whenever I run this it doesn't seem to work.
Here's the script that's on the seats
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using PixelCrushers.DialogueSystem;
public class dropitem : MonoBehaviour, IDropHandler
{
public string check;
public bool correct;
private Dragdrop dragDrop;
void Awake()
{
dragDrop = GetComponent<Dragdrop>();
}
public void OnDrop(PointerEventData eventData)
{
if ( dragDrop.name == check)
{
correct = true;
}
Debug.Log("dropped");
if (eventData.pointerDrag != null)
{
eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = GetComponent<RectTransform>().anchoredPosition;
}
}
}
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using PixelCrushers.DialogueSystem;
public class Dragdrop : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IDropHandler
{
private RectTransform rectTransform;
private CanvasGroup canvasGroup;
void start()
{
foreach (Actor NPC in DialogueManager.masterDatabase.actors)
{
string name = DialogueLua.GetActorField(NPC.Name, "Name").asString;
Transform actorTransform = PixelCrushers.DialogueSystem.CharacterInfo.GetRegisteredActorTransform(NPC.Name);
}
}
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
canvasGroup = GetComponent<CanvasGroup>();
}
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("drag");
canvasGroup.blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("isdraggin");
rectTransform.anchoredPosition += eventData.delta;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("no drag");
canvasGroup.blocksRaycasts = true;
}
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("pointdown");
}
public void OnDrop(PointerEventData eventData)
{
}
}
Yet without any of the dialogue manager stuff added, the snap in place function was working and the consol logged it was dropped.NullReferenceException: Object reference not set to an instance of an object
dropitem.OnDrop (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/scripts/dropitem.cs:21)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IDropHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.4.0f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:85)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2019.4.0f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.0f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
Any idea what's causing the kerfuffle? Thanks in advance <3