How would i go about assigning a clone game object (craftSystem) to instantiated prefab?
Instantiated prefab script:
using UnityEngine;
using System.Collections;
public class WorkingStation : MonoBehaviour
{
public KeyCode openInventory;
public GameObject craftSystem;
public int distanceToOpenWorkingStation = 3;
bool showCraftSystem;
Inventory craftInventory;
CraftSystem cS;
// Use this for initialization
void Start()
{
if (craftSystem != null)
{
craftInventory = craftSystem.GetComponent<Inventory>();
cS = craftSystem.GetComponent<CraftSystem>();
}
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance(this.gameObject.transform.position, GameObject.FindGameObjectWithTag("Player").transform.position);
if (Input.GetKeyDown(openInventory) && distance <= distanceToOpenWorkingStation)
{
showCraftSystem = !showCraftSystem;
if (showCraftSystem)
{
craftInventory.openInventory();
}
else
{
cS.backToInventory();
craftInventory.closeInventory();
}
}
if (showCraftSystem && distance > distanceToOpenWorkingStation)
{
cS.backToInventory();
craftInventory.closeInventory();
}
}
}
Code used to instantiate the prefab:
public void SetItem(GameObject b)
{
hasPlaced = false;
currentBuilding = Instantiate(b).transform;
placeableBuilding = currentBuilding.GetComponent<PlaceableBuilding>();
}
Basically what I’m trying to do is a building system and while instantiating works fine the public GameObject craftSystem is empty and dont work.
PS the plubic gameobject is a clone itself in hierarchy