예제 #1
0
 void Update()
 {
     if (Input.GetKeyDown("1"))
     {
         currentBlock = new BlockGrass();
         GetComponent <InventoryManager>().SelectItem(1);
     }
     else if (Input.GetKeyDown("2"))
     {
         currentBlock = new BlockSand();
         GetComponent <InventoryManager>().SelectItem(2);
     }
     else if (Input.GetKeyDown("3"))
     {
         currentBlock = new BlockWood();
         GetComponent <InventoryManager>().SelectItem(3);
     }
     if (Input.GetKeyDown(KeyCode.Q))
     {
         GameObject temp;
         if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.grass)
         {
             temp = Instantiate(item_grass, transform.position + transform.forward, transform.rotation);
             temp.GetComponent <Rigidbody>().AddForce(transform.forward * 3 + new Vector3(0, 1, 0), ForceMode.Impulse);
             GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
         }
         else if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.sand)
         {
             temp = Instantiate(item_sand, transform.position + transform.forward, transform.rotation);
             temp.GetComponent <Rigidbody>().AddForce(transform.forward * 3 + new Vector3(0, 1, 0), ForceMode.Impulse);
             GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
         }
         else if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.wood)
         {
             temp = Instantiate(item_wood, transform.position + transform.forward, transform.rotation);
             temp.GetComponent <Rigidbody>().AddForce(transform.forward * 3 + new Vector3(0, 1, 0), ForceMode.Impulse);
             GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
         }
     }
     if (Input.GetMouseButton(0))
     {
         if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.bow)
         {
             ChargeArrow();
         }
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.pick)
         {
             Mine();
         }
     }
     if (Input.GetMouseButtonUp(0))
     {
         if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.bow)
         {
             FireArrow();
         }
     }
     if (Input.GetMouseButtonDown(1))
     {
         RaycastHit hit;
         //if (Physics.Raycast(transform.position, transform.forward, out hit, 100))
         if (Physics.Raycast(myCam.transform.position, myCam.transform.forward, out hit, 5))
         {
             //EditTerrain.SetBlock(hit, new BlockSand());
             // Get block to the side which faces the player
             //EditTerrain.SetSideBlock(hit, new BlockSand(), false, true);
             if (GetComponent <InventoryManager>().currentTool)
             {
                 if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.grass)
                 {
                     EditTerrain.SetSideBlock(hit, new BlockGrass(), false, true);
                     GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
                 }
                 else if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.sand)
                 {
                     EditTerrain.SetSideBlock(hit, new BlockSand(), false, true);
                     GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
                 }
                 else if (GetComponent <InventoryManager>().currentTool.GetComponent <Item>().type == Item.Items.wood)
                 {
                     EditTerrain.SetSideBlock(hit, new BlockWood(), false, true);
                     GetComponent <InventoryManager>().inv[GetComponent <InventoryManager>().selectedIndex].count--;
                 }
             }
         }
     }
 }