There is a small code when you move an object on the map, in the right place where you can build an entire green object, where you cannot red.
Problem: when I create an object with the help of a button in a place where it is possible to build an object that lights up in red, but when I push an object into the mountains, and then back to level ground, then everything is fine. Those. To build, I need to make the trigger work, how can I get rid of it? And in the update there is a constant check of the material. How can this be removed?
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Unit : MonoBehaviour { public Material matGhostGreen; public Material matGhostRed; public Material matNormal; string tagCreate = "CreateUnit"; string tagComplete = "CompleteUnit"; public bool sBefore = false; public BoxCollider bc1; public BoxCollider bc2; void Start() { GlobalVar.onTriggerUnit = true; } void Update() { Debug.Log("!!!!!!"); if (gameObject.tag == tagCreate) { if ( GlobalVar.onTriggerUnit==false) { gameObject.GetComponentInChildren<MeshRenderer>().material = matGhostGreen; } if(GlobalVar.onTriggerUnit == true) { gameObject.GetComponentInChildren<MeshRenderer>().material = matGhostRed; } } /* if ((gameObject.tag == tagCreate) && (GlobalVar.onTriggerUnit == true)) { gameObject.GetComponentInChildren<MeshRenderer>().material = GhostNone; }*/ if (GlobalVar.activeCreateUnit == false) { gameObject.GetComponentInChildren<MeshRenderer>().material = matNormal; gameObject.tag = tagComplete; bc1.enabled = true; bc2.enabled = false; Destroy(gameObject.GetComponent<Rigidbody>()); } } void OnTriggerEnter() { GlobalVar.onTriggerUnit = true; } void OnTriggerExit() { GlobalVar.onTriggerUnit = false; } void OnTriggerStay(Collider other) { Debug.Log("dfgdgdfg"); // if (other.attachedRigidbody) // { // other.attachedRigidbody.AddForce(Vector3.up * 10); //} } Here is what is hanging on the object, there are two box colliders when, after installing the object, one box will be removed and another will appear but smaller: 
And this is when I walk through the object on the mountain, then you can put: 
