Hi everyone, I have been following a tutorial online but unfortunately, some of the variables he has are not showing in my inspector. Public class buildObjects variables name, prefab, preview and cost.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Building : MonoBehaviour
{
public List<buildObjects> objects = new List<buildObjects>();
public buildObjects currentObject;
private Vector3 currentPos;
public Transform currentPreview;
public Transform cam;
public RaycastHit hit;
public LayerMask layers;
public float offset = 1.0f;
public float gridSize = 1.0f;
public bool IsBuilding;
public void ChangeCurrentBuilding()
{
GameObject curprev = Instantiate(currentObject.preview, currentPos , Quaternion.identity) as GameObject;
currentPreview = curprev.transform;
}
public void startPreview()
{
if (Physics.Raycast(cam.position, cam.forward, out hit, 10, layers))
{
if (hit.transform != this.transform)
{
showPreview(hit);
}
}
}
// Use this for initialization
void Start () {
currentObject = objects [0];
ChangeCurrentBuilding();
}
// Update is called once per frame
void Update () {
if(IsBuilding)
{
startPreview ();
}
if(Input.GetButton("Fire1"))
{
Build();
}
}
public void showPreview(RaycastHit hit2)
{
currentPos = hit2.point;
currentPos -= Vector3.one * offset;
currentPos /= gridSize;
currentPos = new Vector3(Mathf.Round(currentPos.x), Mathf.Round(currentPos.y), Mathf.Round(currentPos.z));
currentPos *= gridSize;
currentPos += Vector3.one * offset;
currentPreview.position = currentPos;
}
public void Build ()
{
previewObject PO = currentPreview.GetComponent<previewObject>();
if(PO.isBuildable)
{
Instantiate (currentObject.prefab, currentPos, Quaternion.identity);
}
}
public class buildObjects
{
public string name;
public GameObject prefab;
public GameObject preview;
public int cost;
}
}