Last active
November 13, 2018 16:44
-
-
Save Avonexile/7bfa6ba39bc7c32a70bc7e04fd456c44 to your computer and use it in GitHub Desktop.
This script is about putting items in slots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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