コード例 #1
0
    public void SpawnPlayerObject(GameObject givenPrefab, InvItem originInvSlot)
    {
        // Don't spawn in an object if the player is already dragging one
        if (!dragScript.draggedObject)
        {
            originInvSlot.startingAmount--;
            originInvSlot.UpdateAmountCounter();

            // Spawn the object, and capture a reference to it in order to add it to spawnedObjects
            GameObject gameObjectInstance = (GameObject)Instantiate(givenPrefab);

            InteractiveObject intObj = gameObjectInstance.GetComponent <InteractiveObject>();
            if (intObj != null)
            {
                intObj.draggable = true;
            }
            else
            {
                Debug.LogError("Spawned object has no interactive object script");
            }

            // Add it to the list of spawnedObjects | m_position is set 0,0,0 since it doesnt
            // really matter as we'll grab the objects final position when the game actually starts
            SpawnedObject newSpawnedObject = new SpawnedObject(gameObjectInstance, originInvSlot.uniqueName, new Vector3(0, 0, 0), givenPrefab, Quaternion.identity, -1);
            spawnedObjects.Add(newSpawnedObject);

            dragScript.forceDraggedObject = true;
            dragScript.SetNewDraggedObject(gameObjectInstance, new Vector2(0, 0));
        }
    }