- Home /
Problem with a Bool
I'm making an inventory for an Adventure Game, but somehow I screwed up my script so that it (the inventory) doesn't render in the Game View. I've tried everything I can think of, but it just won't work. Yet the Sprite Renderer is still on.
I've set it up so that when I click on this Square sprite, the inventory is supposed to pop up. I've verified that the OnMouseDown event is working though. Here is my code:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class InventoryRenderer : MonoBehaviour {
 
     //make sure to parent thie inventory to camera
 
     public Vector3 HidePosition;
     public Vector3 OpenPositon;
     public bool IsUp;
 
     //all positions relative to camera
 
     void Start () {
         IsUp = false;
         transform.localPosition = HidePosition;
     }
 
     void Update () {
         if (IsUp == false) {
             transform.localPosition = HidePosition;
         } else {
             transform.localPosition = OpenPositon;
         }
         
     }
     void MouseEnterEvent() {
 
         print ("Mouse Has Entered Da Thingy");
 
     }
 }
And on the Square sprite's script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class OpenInventory : MonoBehaviour {
 
     GameObject inventory;
     //name the inventory to match this string
     public string InventoryName = "Inventory";
 
     void Start() {
         inventory = GameObject.Find(InventoryName);
     }
     void OnMouseDown() {
 
         print ("You Tulched A Square");
 
         if (inventory.GetComponent<InventoryRenderer> ().IsUp == false) {
             inventory.GetComponent<InventoryRenderer> ().IsUp = true;
         } else {
             inventory.GetComponent<InventoryRenderer> ().IsUp = false;
         }
     }
 
 }
 
Answer by foureyes44 · Apr 17, 2018 at 12:01 AM
Okay, I figured it out. I believe the camera was fixated in a way that made it so that if the z-axis was at zero, the sprite would be behind it (the camera). My HidePosition and OpenPosition variables had 0 on the z-axis, therefore rendering the Inventory behind the camera when the game began running.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                