void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         PlaceableManager.StartPlacing(placeable);
     }
 }
 private void OnPrimaryClick(Vector2 vector2)
 {
     if (!PlaceableManager.Placing)
     {
         PlaceableManager.StartPlacing(GridTilePlaceable);
     }
 }
 public override void OnPlacementConfirm(GridPosition gridPos, Vector3 worldPos)
 {
     CheckTile(gridPos);
     if (placingTile)
     {
         placingTile.Position = gridPos;
         placingTile.gameObject.SetActive(true);
     }
     placingTile = null;
     PlaceableManager.StopPlacing();
 }
 void Start()
 {
     try
     {
         objMgrScript = GameObject.Find("PlaceableManager").GetComponent <PlaceableManager>();
     }
     catch (NullReferenceException e)
     {
         // If there is no placeable manager game object, create one...
         // Create a game object with the PlaceableManager script attached
         GameObject pMgrObj = new GameObject();
         pMgrObj.AddComponent <PlaceableManager>();
         pMgrObj.name = "PlaceableManager";
         //Instantiate(pMgrObj);
         objMgrScript = pMgrObj.GetComponent <PlaceableManager>();
     }
 }
    /// <summary>
    /// Handles what should happen when the game is resumed.
    /// </summary>
    void ResumeGame()
    {
        isPaused = false;
        //========== UNFREEZE THE PLAYER =================
        // Allow the player to continue moving
        player.enabled = true;
        // Unfreeze the player's rigidbody
        player.gameObject.GetComponent <Rigidbody>().WakeUp();
        // Allow the player to resume animating
        player.GetComponent <Animator>().enabled = true;
        //===============================================

        //======= UNFREEZE ALL OTHER CHARACTERS ==========
        // Disable all other characters
        if (enemies != null)
        {
            foreach (BaseCharacter b in enemies)
            {
                b.enabled = true;
                b.gameObject.GetComponent <Rigidbody>().WakeUp();
                b.GetComponent <Animator>().enabled = true;
            }
        }
        //================================================

        //======== ENABLE MANAGERS======================
        try
        {
            // Stop spawning placeable objects
            PlaceableManager placeableManager = GameObject.Find("PlaceableManager").GetComponent <PlaceableManager>();
            placeableManager.enabled = true;
        }
        catch (NullReferenceException e)
        {
            Debug.Log("You are missing one or more managers. Alternatively check the spelling of the game object name.\n" + e);
        }
        //=============================================
    }
    void DisableScene()
    {
        try
        {
            // Stop spawning placeable objects
            PlaceableManager placeableManager = GameObject.Find("PlaceableManager").GetComponent <PlaceableManager>();
            placeableManager.enabled = false;

            // Disable all other characters
            if (enemies != null)
            {
                foreach (BaseCharacter b in enemies)
                {
                    b.enabled = false;
                    b.gameObject.GetComponent <Rigidbody>().Sleep();
                    b.GetComponent <Animator>().enabled = false;
                }
            }
        }
        catch (NullReferenceException e)
        {
            Debug.Log("You are missing one or more managers. Alternatively check the spelling of the game object name.\n" + e);
        }
    }
    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!");
            }
        }
    }
 protected virtual void Awake()
 {
     cam          = GameObject.Find("Main Camera").GetComponent <Camera>();
     placeableMgr = GameObject.Find("PlaceableManager").GetComponent <PlaceableManager>();
     gameObject.SetActive(false);
 }
Example #9
0
 private void Awake()
 {
     placeable = gameObject.GetComponent <PlaceableManager>();
 }