File size: 1,845 Bytes
3497d64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GhostItem : MonoBehaviour
{
public BoxCollider solidCollider; // set manually
public Renderer mRenderer;
private Material semiTransparentMat; // Used for debug - insted of the full trasparent
private Material fullTransparentnMat;
private Material selectedMaterial;
public bool isPlaced;
// A flag for the deletion algorithm
public bool hasSamePosition = false;
private void Start()
{
mRenderer = GetComponent<Renderer>();
// We get them from the manager, because this way the referece always exists.
semiTransparentMat = ConstructionManager.Instance.ghostSemiTransparentMat;
fullTransparentnMat = ConstructionManager.Instance.ghostFullTransparentMat;
selectedMaterial = ConstructionManager.Instance.ghostSelectedMat;
mRenderer.material = semiTransparentMat; //change to semi if in debug else full
// We disable the solid box collider - while it is not yet placed
// (unless we are in construction mode - see update method)
solidCollider.enabled = false;
}
private void Update()
{
// We need the solid collider so the ray cast will detect it
if (ConstructionManager.Instance.inConstructionMode && isPlaced)
{
solidCollider.enabled = true;
}
if (!ConstructionManager.Instance.inConstructionMode)
{
solidCollider.enabled = false;
}
// Triggering the material
if(ConstructionManager.Instance.selectedGhost == this.gameObject)
{
mRenderer.material = selectedMaterial;
}
else
{
mRenderer.material = semiTransparentMat; //change to semi if in debug else full
}
}
} |