public void ChangeObjMat(GameObject obj, Material newMat)
This will loop through all children of the obj including itself and through all assigned materials and assign the newMat to each of them.
//Changes the obj material to something else.
GridSelector gridSelector;
void Start()
{
gridSelector.ChangeObjMat(myObjectToChange, invalidMaterial);
}
public void DeselectPreview()
This function destroys the preview object from the hierarchy and sets the object to place as null.
//Remove the previewing of the object assigned when pressing escape.
GridSelector gridSelector;
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
gridSelector.DeselectPreview();
}
}
public void SetGameObjectToPlace(GameObject obj)
This simply takes in the obj, and sets it for the Grid Selector to preview or place the object.
//Takes an object from a button to place on the grid selector.
GridSelector gridSelector;
//The prefab to send to the grid selector to place
public GameObject prefab;
void Awake()
{
btn = GetComponent<Button>();
}
void Start()
{
btn.onClick.AddListener(() => {
gridSelector.SetGameObjectToPlace(prefab);
});
}
public Vector3 GetSelectorPosition()
This returns the current clamped position of the grid selector. This value can then be used to find out if the cell is free using gridSquare.CheckCellStatus(Vector3 cellPos).
//Debugs the current clamped grid selector position
GridSelector gridSelector;
void Update()
{
Debug.Log(gridSelector.GetSelectorPosition());
}