evelynshilosky

GhostItem - Part 31

Feb 1st, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GhostItem : MonoBehaviour
  6. {
  7.     public BoxCollider solidCollider; // set manually
  8.  
  9.     public Renderer mRenderer;
  10.     private Material semiTransparentMat; // Used for debug - insted of the full trasparent
  11.     private Material fullTransparentMat;
  12.     private Material selectedMaterial;
  13.  
  14.     public bool isPlaced;
  15.  
  16.     // A flag for the deletion algorithm
  17.     public bool hasSamePosition = false;
  18.     private void Start()
  19.     {
  20.         mRenderer = GetComponent<Renderer>();
  21.         // We get them from the manager, because this way the referece always exists.
  22.         semiTransparentMat = ConstructionManager.Instance.ghostSemiTransparentMat;
  23.         fullTransparentMat = ConstructionManager.Instance.ghostFullTransparentMat;
  24.         selectedMaterial = ConstructionManager.Instance.ghostSelectedMat;
  25.  
  26.         mRenderer.material = fullTransparentMat; //change to semi if in debug else full
  27.         // We disable the solid box collider - while it is not yet placed
  28.         // (unless we are in construction mode - see update method)
  29.         solidCollider.enabled = false;
  30.     }
  31.  
  32.     private void Update()
  33.     {
  34.  
  35.         if (ConstructionManager.Instance.inConstructionMode)
  36.         {
  37.             Physics.IgnoreCollision(gameObject.GetComponent<Collider>(), ConstructionManager.Instance.player.GetComponent<Collider>());
  38.         }
  39.  
  40.  
  41.  
  42.  
  43.         // We need the solid collider so the ray cast will detect it
  44.         if (ConstructionManager.Instance.inConstructionMode && isPlaced)
  45.         {
  46.             solidCollider.enabled = true;
  47.         }
  48.  
  49.         if (!ConstructionManager.Instance.inConstructionMode)
  50.         {
  51.             solidCollider.enabled = false;
  52.         }
  53.  
  54.         // Triggering the material
  55.         if (ConstructionManager.Instance.selectedGhost == this.gameObject)
  56.         {
  57.             mRenderer.material = selectedMaterial;
  58.         }
  59.         else
  60.         {
  61.             mRenderer.material = fullTransparentMat; //change to semi if in debug else full
  62.         }
  63.     }
  64. }
  65.  
Add Comment
Please, Sign In to add comment