Forum rules - please read before posting.

Unusual Delay during Inventory Interactions & Different Way to Switch Player

2»

Comments

  • Here is an example, notice the yellow bed's amount is set to 10.

    The video's quality is too low for me to make out any numbers on the items, but this amended script should prevent the error:

    using UnityEngine;

    namespace AC
    {
    
        public class FurniturePiece : MonoBehaviour
        {
    
            [SerializeField] private int associatedItemID = 0;
            private FurniturePiece[] allPieces;
    
            void OnEnable ()
            {
                EventManager.OnInventorySelect += OnInventorySelect;
                EventManager.OnInventoryDeselect_Alt += OnInventoryDeselect;
            }
    
            void OnDisable ()
            {
                EventManager.OnInventorySelect -= OnInventorySelect;
                EventManager.OnInventoryDeselect_Alt -= OnInventoryDeselect;
            }
    
            void Start ()
            {
                allPieces = Object.FindObjectsOfType <FurniturePiece>();
            }
    
            void Update ()
            {
                if (KickStarter.runtimeInventory.SelectedItem != null && KickStarter.runtimeInventory.SelectedItem.id == associatedItemID)
                {
                    float cameraDepth = transform.position.z - Camera.main.transform.position.z;
                    Vector3 screenPosition = new Vector3 (KickStarter.playerInput.GetMousePosition ().x, KickStarter.playerInput.GetMousePosition ().y, cameraDepth);
                    transform.position = Camera.main.ScreenToWorldPoint (screenPosition);
                }
            }
    
            void OnInventorySelect (InvItem item)
            {
                if (item.id == associatedItemID)
                {
                    int maxOrder = 0;
                    foreach (FurniturePiece piece in allPieces)
                    {
                        if (piece == this) continue;
                        maxOrder = Mathf.Max (maxOrder, piece.GetComponent <SpriteRenderer>().sortingOrder);
                    }
    
                    GetComponent <SpriteRenderer>().sortingOrder = maxOrder + 1;
                }
            }
    
            void OnInventoryDeselect (InvCollection invCollection, InvInstance invInstance)
            {
                if (invCollection != null && invInstance.ItemID == associatedItemID)
                {
                    invCollection.Delete (invInstance, 1);
                }
            }
    
        }
    
    }
    

    Everything is set up well except the speech does not show in the scene when the item is being hovered over.

    The item's property ID is not 51, but 0.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.