87 lines
2.2 KiB
C#
87 lines
2.2 KiB
C#
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
public class CraftingTable : MonoBehaviour
|
|
{
|
|
public Transform item1;
|
|
public Transform item2;
|
|
|
|
public Transform socket1;
|
|
public Transform socket2;
|
|
|
|
public Transform output;
|
|
public GameObject startWand;
|
|
|
|
void Start()
|
|
{
|
|
item1 = null;
|
|
item2 = null;
|
|
}
|
|
|
|
|
|
public void Set1()
|
|
{
|
|
StartCoroutine(DelayCast(socket1,1));
|
|
}
|
|
|
|
public void Exit1()
|
|
{
|
|
item1 = null;
|
|
}
|
|
|
|
public void Set2()
|
|
{
|
|
StartCoroutine(DelayCast(socket2, 2));
|
|
}
|
|
|
|
public void Exit2()
|
|
{
|
|
item2 = null;
|
|
}
|
|
|
|
public void Craft()
|
|
{
|
|
//Currently simple if statement check crafting. Could be done better but will see if this system will be expanded
|
|
|
|
if (item1 == null || item2 == null) Debug.LogError("Missing item!");
|
|
else
|
|
{
|
|
if((item1.name.StartsWith("wand") && item2.name.StartsWith("Log")) || (item2.name.StartsWith("wand") && item1.name.StartsWith("Log")))
|
|
{
|
|
if (item1.name.StartsWith("wand"))
|
|
{
|
|
WandData data = item1.GetComponent<WandData>();
|
|
data.SetPower(data.power + 0.5f);
|
|
item1.transform.position = output.position;
|
|
Destroy(item2.gameObject);
|
|
item2 = null;
|
|
}
|
|
else
|
|
{
|
|
WandData data = item2.GetComponent<WandData>();
|
|
data.SetPower(data.power + 0.5f);
|
|
item2.transform.position = output.position;
|
|
Destroy(item1.gameObject);
|
|
item1 = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
Debug.LogError("Invalid Recipe!");
|
|
}
|
|
|
|
IEnumerator DelayCast(Transform from, int i)
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(from.position + from.up, -from.up, out hit, Mathf.Infinity))
|
|
{
|
|
if (i == 1) item1 = hit.transform;
|
|
else item2 = hit.transform;
|
|
}
|
|
}
|
|
}
|