예제 #1
0
    /// <summary>
    /// Try to place a building.
    /// </summary>
    /// <param name="prefab">The GameObject to place</param>
    public void Build(GameObject prefab)
    {
        prefab.layer = 0;                                                                       //Set to default Layer
        InHand inHand = prefab.GetComponent <InHand>();                                         //Get a reference to the in-hand component

        if (inHand == null || !inHand.validPlacement || inHand.CheckCollision())                //Check if everything is clear
        {
            if (buildKeyDownTime > InvalidBuildTimeThreshold)                                   //Have we been trying to build here long?
            {
                ShowMessage("Can't build here");                                                //Give player more feedback
            }
            return;                                                                             //Don't do anything else
        }
        string Pay = CanWePayFor(prefab);                                                       //Create a new string, will return what we are missing if we can't build

        if (Pay == "Done")                                                                      //If we do have enough to build this building
        {
            GameObject building = Instantiate(prefab);                                          //Clone the prefab as a new building
            building.layer = LayerMask.NameToLayer("Building");                                 //Set this to be in the building layer (so we can't build on this anymore)
            building.transform.SetParent(FolderBuildings);                                      //Sort the building in the right folder
            building.GetComponent <BuildingOption>().StartTimer();                              //Start the 'Used' after timer if this object
            building.GetComponent <BuildingOption>().OwnerID = ThisPlayerID;                    //Set the current player to be the owner of this building
            Destroy(building.GetComponent <InHand>());                                          //Remove the in-hand component
        }
        else
        {
            ShowMessage("Not enough " + Pay + " to build that");                                //Give the user the warning message
        }
    }
예제 #2
0
        public void StoreItemInHand()
        {
            Item toStore = InHand[0];

            InHand.Remove(toStore);
            Inventory.Add(toStore);
            toStore.ItemState = ItemStates.InBackpack;
        }
예제 #3
0
    /// <summary>
    /// Try to place a building.
    /// </summary>
    /// <param name="prefab">The GameObject to place</param>
    public void Build(GameObject prefab)
    {
        prefab.layer = 0;                                                                       //Set to default Layer
        InHand inHand = prefab.GetComponent <InHand>();                                         //Get a reference to the in-hand component

        if (inHand == null || !inHand.validPlacement || inHand.CheckCollision())                //Check if everything is clear
        {
            if (BuildFirstTry)                                                                  //If the user is starting to trying to build
            {
                ShowMessage("Can't build here ");                                               //Give player more feedback
                BuildFirstTry = false;                                                          //Flag that we have processed the start of this button press
            }
            if (buildKeyDownTime > InvalidBuildTimeThreshold)                                   //Have we been trying to build here long?
            {
                ShowMessage("Can't build here ");                                               //Give player more feedback
            }
            return;                                                                             //Don't do anything else
        }
        string Pay = CanWePayFor(prefab);                                                       //Create a new string, will return what we are missing if we can't build

        if (Pay == "Done")                                                                      //If we do have enough to build this building
        {
            BuildFirstTry    = false;                                                           //Flag that we have processed the start of this button press
            buildKeyDownTime = 0;                                                               //Reset the message timer (this if for keep dragging support)
            if (inHand.RemoveObjectsHit.Count > 0)                                              //If there are objects we need to remove
            {
                for (int i = 0; i < inHand.RemoveObjectsHit.Count; i++)                         //Do for each object
                {
                    DeconstructBuilding(inHand.RemoveObjectsHit[i]);                            //Deconstruct the building
                }
            }
            GameObject building = Instantiate(prefab);                                          //Clone the prefab as a new building
            building.layer = LayerMask.NameToLayer("Building");                                 //Set this to be in the building layer (so we can't build on this anymore)
            building.transform.SetParent(FolderBuildings);                                      //Sort the building in the right folder
            building.GetComponent <BuildingOption>().StartTimer();                              //Start the 'Used' after timer if this object
            building.GetComponent <BuildingOption>().OwnerID = ThisPlayerID;                    //Set the current player to be the owner of this building
            Destroy(building.GetComponent <InHand>());                                          //Remove the in-hand component
        }
        else
        {
            ShowMessage("Not enough " + Pay + " to build that");                                //Give the user the warning message
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveForward();
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBackwards();
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft();
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight();
        }

        if (Input.GetKeyDown(KeyCode.RightShift))
        {
            currently_Holding = Interact();
        }

        //Iventory system

        if (currently_Holding == InHand.Plucker)
        {
            Shovel_item_player_2.SetActive(true);
        }

        if (currently_Holding == InHand.Tomatoes)
        {
            tomatoes_item_player_2.SetActive(true);
        }

        if (currently_Holding == InHand.Tomatoe_Seeds)
        {
            tomato_seeds_item_player_2.SetActive(true);
        }

        if (currently_Holding == InHand.Carrot_Seeds)
        {
            carrots_seeds_item_player_2.SetActive(true);
        }

        if (currently_Holding == InHand.Carrots)
        {
            carrots_item_player_2.SetActive(true);
        }


        if (currently_Holding == InHand.Empty)
        {
            tomato_seeds_item_player_2.SetActive(false);
            tomatoes_item_player_2.SetActive(false);
            carrots_item_player_2.SetActive(false);
            carrots_seeds_item_player_2.SetActive(false);
            Shovel_item_player_2.SetActive(false);
        }
    }
예제 #5
0
 /// <summary>
 ///   Place a certain item type on to another ICanHoldItem. **NOT IMPLEMENTED**
 /// </summary>
 /// <param name = "item">The item to place.</param>
 public void PutdownItem(Item item)
 {
     InHand.Remove(item);
 }
예제 #6
0
 /// <summary>
 ///   Pick up an item and place into this actors inventory.
 /// </summary>
 /// <param name = "item">The item to pick up.</param>
 public ItemStates PickupItem(Item item)
 {
     InHand.Add(item);
     return(ItemStates.BeingCarried);
 }