Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i get the Block you destroyed (for a inventory that workes with IDs) #66

Open
GaimeWolves opened this issue Apr 4, 2016 · 1 comment
Labels

Comments

@GaimeWolves
Copy link

GaimeWolves commented Apr 4, 2016

I have an inventory system which works with IDs

public Inventory inventory;
/...
inventory.AddItem(ID);
.../

how can i assign IDs to the individual Blocks and read them from another script (the block breacking script working with RayCast)

@alex-irt
Copy link
Collaborator

alex-irt commented Apr 6, 2016

Voxelmetric (all versions) has ids for each block type. You could use:

item.id = block.type;

The voxel tutorial from my website does not have ids for block types. You could implement your own ids like this:

  //block.cs
  using System.Collections.Generic;

  public class Block
  {
    private static Dictionary<Type, int> blockIds = new Dictionary<Type, int>()
    {
        { typeof(Block), 0},
        { typeof(BlockAir), 1},
        { typeof(BlockGrass), 30},
        { typeof(BlockLeaves), 93},
        { typeof(BlockWood), 12}
    };

    public int id { get { return blockIds[GetType()]; } }

  ...

This will let you use any id you want for each block to match whatever you're using for the inventory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants