Skip to content

Instantly share code, notes, and snippets.

@Avonexile
Last active November 13, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avonexile/7bfa6ba39bc7c32a70bc7e04fd456c44 to your computer and use it in GitHub Desktop.
Save Avonexile/7bfa6ba39bc7c32a70bc7e04fd456c44 to your computer and use it in GitHub Desktop.
This script is about putting items in slots
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
namespace CraftingSystemRework
{
public class SelectionManager : MonoBehaviour {
//object selected
public GameObject selectedObject, lastSelectedObject;
public GameObject selectedSlot, lastSelectedSlot;
public GameObject rando;
public Slot selectedSlotscript;
public CraftSlot selectedCraftSlotscript;
public Inventory inventory;
//keeps checking if you deselect
void Update ()
{
CheckInput();
}
//checks if you deselect a item
public void CheckInput ()
{
if(Input.GetButtonDown("Fire2"))
{
Deselect();
}
}
//selects an object and making references to its parents scripts
public void Select (GameObject go)
{
if(selectedObject != null)
{
lastSelectedObject = selectedObject;
}
selectedObject = go;
selectedCraftSlotscript = selectedObject.GetComponentInParent<CraftSlot>();
selectedSlotscript = selectedObject.GetComponentInParent<Slot>();
}
//makes the select object null
public void Deselect ()
{
lastSelectedObject = selectedObject;
selectedObject = null;
}
//childs the item to a slot if the slot is empty
public void ChildItem (GameObject go)
{
if(selectedSlot != null)
{
lastSelectedSlot = selectedSlot;
}
selectedSlot = go;
if(selectedSlot.tag == "Slot")
{
if(selectedSlot.gameObject.transform.childCount == 0)
{
selectedObject.transform.parent = null;
selectedObject.transform.SetParent(go.transform);
selectedObject.GetComponent<Item>().Checks();
}
}
if(selectedSlot.tag == "Craft Slot")
{
if(selectedSlot.gameObject.transform.childCount == 0)
{
selectedObject.transform.parent = null;
selectedObject.transform.SetParent(go.transform);
selectedObject.GetComponent<Item>().Checks();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment