Пример #1
0
    private void ProduceResource()
    {
        Vector3    offset2  = Random.Range(-2f, 2f) * Vector3.forward;
        GameObject resource = Instantiate(validateObject.InstantiateFinalObject(this.gameObject)) as GameObject;

        //Object location at mining source
        resource.transform.position = transform.position + offset2 + new Vector3(0, 0.2f, 0);
        resource.SetActive(true);
        resource.name = validateObject.nameFinalObject(this.gameObject);
        EventTrigger objectTrigger = item.GetComponent <EventTrigger> ();

        objectTrigger.enabled = false;
        objectsFromInventoryCount++;
    }
Пример #2
0
 void InteractFromInventory()
 {
     //Pull object from inventory to interact
     for (int i = 0; i < inventory.inventory.Count; i++)
     {
         // Check if object is a valid object to interact with
         if (inventory.inventory [i])
         {
             if (validateObject.IsObjectValidForInteraction(this.gameObject, inventory.inventory [i]))
             {
                 // Increment counter
                 objectsFromInventoryCount++;
                 objectName = inventory.inventory [i].name;
             }
         }
     }
     // If player has all the elements, instantiate final object and destroy current one
     if (objectsFromInventoryCount >= numberOfObjectsToBeAdded)
     {
         //item = validateObject.InstantiateFinalObject (this.gameObject) as GameObject;
         GameObject item = Instantiate(validateObject.InstantiateFinalObject(this.gameObject)) as GameObject;
         item.transform.position = transform.position;
         item.name = validateObject.nameFinalObject(this.gameObject);
         StartCoroutine(PlaySuccessAndDestroy(item));
         // Remove objects from inventory (numberOfObjectToBeAdded).
         objectsFromInventoryCount = 0;
         for (int i = 0; i < inventory.inventory.Count; i++)
         {
             if (inventory.inventory [i])
             {
                 if (objectsFromInventoryCount < numberOfObjectsToBeAdded && validateObject.IsObjectValidForInteraction(this.gameObject, inventory.inventory [i]))
                 {
                     objectsFromInventoryCount++;
                     inventory.inventory [i] = null;
                 }
             }
         }
     }
     else if (objectName != null)
     {
         numberOfObjectsMissing = numberOfObjectsToBeAdded - objectsFromInventoryCount;
         StartCoroutine(displayCanvas.DisplayInteractGUI(objectName, numberOfObjectsMissing));
     }
     objectsFromInventoryCount = 0;
 }