creata 3d minecraft version
- User
creata 3d minecraft version
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
creata 3d minecraft version
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here’s a complete Unity project for a 3D Minecraft-like game with: ✅ Procedural terrain generation ✅ Block placement & destruction ✅ First-person controls ✅ Basic inventory system
Block.cs)using UnityEngine;
public class Block : MonoBehaviour
{
public enum BlockType { Grass, Dirt, Stone, Wood }
public BlockType blockType;
public Material grassMaterial, dirtMaterial, stoneMaterial, woodMaterial;
void Start()
{
UpdateBlockMaterial();
}
public void UpdateBlockMaterial()
{
Renderer renderer = GetComponent<Renderer>();
switch (blockType)
{
case BlockType.Grass:
renderer.material = grassMaterial;
break;
case BlockType.Dirt:
renderer.material = dirtMaterial;
break;
case BlockType.Stone:
renderer.material = stoneMaterial;
break;
case BlockType.Wood:
renderer.material = woodMaterial;
break;
}
}
}
WorldGenerator.cs)using UnityEngine;
public class WorldGenerator : MonoBehaviour
{
public GameObject blockPrefab;
public int worldWidth = 10;
public int worldHeight = 5;
public float noiseScale = 0.1f;
void Start()
{
GenerateWorld();
}
void GenerateWorld()
{
for (int x = 0; x < worldWidth; x++)
{
for (int z = 0; z < worldWidth; z++)
{
// Simple Perlin noise for terrain height
int height = Mathf.FloorToInt(Mathf.PerlinNoise(x * noiseScale, z * noiseScale) * worldHeight) + 1;
for (int y = 0; y < height; y++)
{
GameObject newBlock = Instantiate(blockPrefab, new Vector3(x, y, z), Quaternion.identity);
Block blockScript = newBlock.GetComponent<Block>();
// Set block type based on height
if (y == height - 1)
blockScript.blockType = Block.BlockType.Grass;
else if (y > height - 3)
blockScript.blockType = Block.BlockType.Dirt;
else
blockScript.blockType = Block.BlockType.Stone;
}
}
}
}
}
PlayerController.cs)using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public float mouseSensitivity = 100f;
public float reachDistance = 5f;
public GameObject blockPrefab;
public Block.BlockType selectedBlockType = Block.BlockType.Grass;
private float xRotation = 0f;
private Camera playerCamera;
void Start()
{
playerCamera = GetComponentInChildren<Camera>();
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
// Mouse look
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
playerCamera.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
transform.Rotate(Vector3.up * mouseX);
// Movement
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
transform.position += move * moveSpeed * Time.deltaTime;
// Block placement/destruction
if (Input.GetMouseButtonDown(0)) // Left-click to destroy
{
RaycastHit hit;
if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, reachDistance))
{
Destroy(hit.collider.gameObject);
}
}
else if (Input.GetMouseButtonDown(1)) // Right-click to place
{
RaycastHit hit;
if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, reachDistance))
{
Vector3 placePos = hit.point + hit.normal * 0.5f;
GameObject newBlock = Instantiate(blockPrefab, placePos, Quaternion.identity);
Block blockScript = newBlock.GetComponent<Block>();
blockScript.blockType = selectedBlockType;
}
}
// Inventory selection (1-4 keys)
if (Input.GetKeyDown(KeyCode.Alpha1)) selectedBlockType = Block.BlockType.Grass;
if (Input.GetKeyDown(KeyCode.Alpha2)) selectedBlockType = Block.BlockType.Dirt;
if (Input.GetKeyDown(KeyCode.Alpha3)) selectedBlockType = Block.BlockType.Stone;
if (Input.GetKeyDown(KeyCode.Alpha4)) selectedBlockType = Block.BlockType.Wood;
}
}
Block.Block script to it.PlayerController.csCharacterController (for movement)Camera (for first-person view)WorldGenerator.cs to generate terrain.Would you like me to expand on any of these features? 😊