コード例 #1
0
    void CheckRightClick()
    {
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2.0f, Screen.height / 2.0f, 0));

            if (Physics.Raycast(ray, out hit, 6.0f))
            {
                MeshCollider collider = hit.collider as MeshCollider;
                if (collider != null)
                {
                    Mesh mesh = collider.sharedMesh;

                    // Debug.DrawRay(player.transform.position, hit.point - player.transform.position);
                    int index = hit.triangleIndex * 3;

                    Vector3 hit1 = mesh.vertices[mesh.triangles[index]];
                    Vector3 hit2 = mesh.vertices[mesh.triangles[index + 1]];
                    Vector3 hit3 = mesh.vertices[mesh.triangles[index + 2]];

                    Vector3 blockPos = getHitObjectPos(hit1, hit2, hit3, hit.normal);
                    Vector3 newPos   = blockPos + hit.normal;

                    if ((player.transform.position.x < newPos.x + 0.5f && player.transform.position.x > newPos.x - 0.5f) &&
                        (player.transform.position.y < newPos.y + 0.5f && player.transform.position.y > newPos.y - 0.5f) &&
                        (player.transform.position.z < newPos.z + 0.5f && player.transform.position.z > newPos.z - 0.5f))
                    {
                        // Debug.Log ("Inside");
                        return;
                    }

                    if (newPos.y >= 128)
                    {
                        return;
                    }

                    Item item = inventoryBarController.getSelectedItem();
                    if (item != null && item.itemType == ItemType.CUBE_BLOCK)
                    {
                        Block block = (Block)item;
                        world.addBlock(newPos, block, true);

                        chunkChanged = true;
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: PlayerController.cs プロジェクト: shd101wyy/Lone
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1) ||
         Input.GetKeyDown(KeyCode.Alpha2) ||
         Input.GetKeyDown(KeyCode.Alpha3) ||
         Input.GetKeyDown(KeyCode.Alpha4) ||
         Input.GetKeyDown(KeyCode.Alpha5) ||
         Input.GetKeyDown(KeyCode.Alpha6) ||
         Input.GetKeyDown(KeyCode.Alpha7) ||
         Input.GetKeyDown(KeyCode.Alpha8) ||
         Input.GetKeyDown(KeyCode.Alpha9))
     {
         Item item = inventoryBarController.getSelectedItem();
         rightHandHoldItem.generate3DMesh(item);
     }
 }