- Home /
Voxel Engine Coding Blocks?
Hi. I have recently got a voxel engine that I found on YouTube(Here) and I have worked out how to add blocks, and generate them in the world, but I didn't know how I would go about coding a block to do something. In this case, I would like to add a furnace that has a GUI, and the front texture changes when something is in it. I don't want a whole piece of code or anything, but snippets or pointers in the right direction would be a great help.
Thanks
AshJack.
$$anonymous$$ake the furnace gui on the player, and then activate it with Send$$anonymous$$essage, this will greatly optimize and reduce bugs.
I'm guessing you will use First Person, use raycasts sent from the player ins$$anonymous$$d of On$$anonymous$$ouseDown(), I found that On$$anonymous$$ouseDown does not work with the FirstPerson.
$$anonymous$$ake it that when the RayCast hit is there, there is a furnace tag as the hit's collider tag, and if Input $$anonymous$$ouse1 is clicked, the gui is active on the player, then give a Ienumarator, that times the furnace glow, by using sendmessage to a void on the furnace, and then the sentmessage-void triggerss the Ienum.
I hope that helps!
Thanks for the reply. How do you think is best to create the GUI? By script or by GUITexture? Also, I have looked at the scene while the game is in play, and the game registers the chunks only, not each individual block, so I don't know how to make the furnace an exception to this rule.
I would make a general GUI Script. It contains the furnace, crafting and other ui and it would be on the player(rendering too much gui is not good, even if you cannot see it!).
Use sendmessage to activate it.
Also I know that chunks are how the world generates, but user-placed blocks are not chunks, right?
Annoyingly, I thought that too, but a user placed block is added directly to the chunk. Thanks for the advice on GUI.
I have found a file called Blocks.cs, and it registers some types of blocks, could I use this to find the furnace (It is called fireplace in the code):
using UnityEngine;
using System.Collections;
public class Blocks {
public const string Dirt = "Dirt", Grass = "Grass", Snow = "Snow";
public const string Sand = "Sand", Stone = "Stone";
public const string Water = "Water", Ice = "Ice", Fire = "Fire";
public const string Wood = "Wood", Leaves = "Leaves";
public const string Cactus = "Cactus", Pumpkin = "Pumpkin", Flower = "Flower", Fungus = "Fungus";
public const string Bricks = "Bricks", TNT = "TNT", Fireplace = "Fireplace";
}
Your answer
Follow this Question
Related Questions
press e to speek -1 Answers
Snow based questions 2 Answers
Need help converting Javascript to C# 3 Answers
Talking Code 2 Answers
Multiple Cars not working 1 Answer