- Home /
Question by
unity_5B42B79E1C1B7EDE5895 · May 23 at 01:51 PM ·
scripting problemvariableseventsdrag-and-drop
I'm unable to clear a variable that is used in multiple scripts.
Context is I watched a "drag and drop" tutorial and everything is great. Except for one thing. When I drag the object onto another object, which I called a "slot", the slot takes the dragged object's text name and I set a variable called cmdname
and set it to the text. I run the cmdname
as a coroutine afterward.
What I'm unable to do is when I drag the object off of the slot, the cmdname
remains set on the previous dragged object's text. I want to clear the variable so that when the slot is emptied it doesn't run anything.
CommandSlot script that sets the cmdname
:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
#pragma warning disable 618, 649
namespace UnityStandardAssets.Characters.FirstPerson {
public class CommandSlot_1 : MonoBehaviour, IDropHandler
{
public GameObject botInsMenu;
public Bot_Ins_Menu botInsMenuScr;
//public bool onSlot = false;
public string cmdname;
private void Start() {
botInsMenuScr = botInsMenu.GetComponent<Bot_Ins_Menu>();
}
public void OnDrop(PointerEventData eventData) {
Debug.Log("OnDrop");
if (eventData.pointerDrag != null) {
eventData.pointerDrag.GetComponent<RectTransform>().anchoredPosition = GetComponent<RectTransform>().anchoredPosition;
cmdname = eventData.pointerDrag.name;
//botInsMenuScr.funcs.Add("Move10UnitsBack");
//botInsMenuScr.funcs.Add("Jump");
}
}
}
}
How can I check if the slot is emptied so I can set my cmdname to null or something?
Comment