protected virtual void Awake() { if (GetComponent <Rigidbody>() == null) { AddRigidBody(); } if (GetComponent <BoxCollider>() == null || GetComponentInChildren <BoxCollider>() == null) { AddBoxCollider(); } floorMask = LayerMask.GetMask("Floor"); // Get the mask from the Floor layer // Remove '(Clone)' from the GameObject name gameObject.name = name.Remove(name.IndexOf('(')); placeableMgrScript = GameObject.Find("PlaceableManager").GetComponent <PlaceableManager>(); // Number of this placeable type in the scene has increased placeableMgrScript.IncrementObjCount(gameObject); // Notify the manager that this object has yet to be placed, so no new placeable objects can be spawned placeableMgrScript.CanSpawn = false; // If there is a renderer component in the main game object, I assume there is no children if (GetComponent <Renderer>() != null) { renderers.Add(GetComponent <Renderer>()); } else { // Obtain the renders from the children Renderer[] tempRenderer = GetComponentsInChildren <Renderer>(); if (tempRenderer != null) { foreach (Renderer r in tempRenderer) { renderers.Add(r); } } } // Add the initial model materials to the list foreach (Renderer r in renderers) { matInitColours.Add(r.material.color); } ApplyCanPlaceShader(); // Get the NavMeshObstacles if (GetComponent <NavMeshObstacle>() != null) { navObstacles.Add(GetComponent <NavMeshObstacle>()); } else { // Obtain all the navMeshObstacles components from the children NavMeshObstacle[] tempObstacles = GetComponentsInChildren <NavMeshObstacle>(); if (tempObstacles != null) { foreach (NavMeshObstacle o in tempObstacles) { navObstacles.Add(o); } } if (navObstacles.Count == 0) { Debug.Log("There is no NavMeshObstacle component added to the " + gameObject.name + " GameObject!"); } } }