Ejemplo n.º 1
0
    void Look()
    {
        transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * RotateSpeed);
        Eye.Rotate(Vector3.left * Input.GetAxis("Mouse Y") * RotateSpeed);

        RaycastHit hit;

        if (Physics.Raycast(Eye.position, Eye.forward, out hit, 10f))
        {
            if (!(lookingObject == hit.collider.gameObject))
            {
                ClearLookingObject();

                lookingObject = hit.collider.gameObject;
                var mesh = lookingObject.GetComponent <MeshRenderer>();
                if (mesh != null)
                {
                    var block = new MaterialPropertyBlock();
                    block.SetColor("_Color", new Color(0.4f, 0.4f, 0.4f, 1));
                    mesh.SetPropertyBlock(block);
                }
            }

            if (Input.GetButtonDown("Punch"))
            {
                Chunk.SetBlock("unicraft:air", LookingBlock.Location);
            }

            if (Input.GetButtonDown("Interact"))
            {
                BlockBase bl;
                if ((bl = BlockRegister.Instance[LookingBlock.BlockId]) is IInteractable)
                {
                    (bl as IInteractable).OnInteract(LookingBlock.Location, this);
                }
                else
                {
                    var candidate = Vector3Int.CeilToInt(LookingBlock.Location + hit.normal);
                    Chunk.SetBlock(UniCraft.BlockIdInHand, candidate);
                }
            }
        }
        else
        {
            ClearLookingObject();
        }
    }