sheld passive sound, initial crafting (2x wood = wand, wand + wood = damage up)
This commit is contained in:
92
Assets/Project Files/Scripts/JoonasP/CraftingTable.cs
Normal file
92
Assets/Project Files/Scripts/JoonasP/CraftingTable.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
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 Transform Get1()
|
||||
{
|
||||
return item1;
|
||||
}
|
||||
|
||||
public void Set2()
|
||||
{
|
||||
StartCoroutine(DelayCast(socket2, 2));
|
||||
}
|
||||
|
||||
public Transform Get2()
|
||||
{
|
||||
return item2;
|
||||
}
|
||||
|
||||
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.SetDamage(data.damage + 0.5f);
|
||||
item1.transform.position = output.position;
|
||||
Destroy(item2.gameObject);
|
||||
item2 = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
WandData data = item2.GetComponent<WandData>();
|
||||
data.SetDamage(data.damage + 0.5f);
|
||||
item2.transform.position = output.position;
|
||||
Destroy(item1.gameObject);
|
||||
item1 = null;
|
||||
}
|
||||
}
|
||||
else if(item1.name.StartsWith("Log") && item2.name.StartsWith("Log"))
|
||||
{
|
||||
Instantiate(startWand, output.position, Quaternion.identity);
|
||||
Destroy(item1.gameObject);
|
||||
Destroy(item2.gameObject);
|
||||
item1 = null;
|
||||
item2 = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/JoonasP/CraftingTable.cs.meta
Normal file
11
Assets/Project Files/Scripts/JoonasP/CraftingTable.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cc30985ba0315045835d44b1b530ed4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Project Files/Scripts/JoonasP/WandData.cs
Normal file
16
Assets/Project Files/Scripts/JoonasP/WandData.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WandData : MonoBehaviour
|
||||
{
|
||||
public float damage = 1f;
|
||||
|
||||
//public string element = "water";
|
||||
|
||||
|
||||
public void SetDamage(float dam)
|
||||
{
|
||||
damage = dam;
|
||||
}
|
||||
}
|
||||
11
Assets/Project Files/Scripts/JoonasP/WandData.cs.meta
Normal file
11
Assets/Project Files/Scripts/JoonasP/WandData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9df026d0ca5cb9c4dbe59181dd93dbdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user