Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: afrokick
- Forum: www.devby.ru
- Video: https://www.youtube.com/watch?v=Zgwv_YZaXJA
- */
- using UnityEngine;
- using System.Collections;
- public class MineCraftController : MonoBehaviour {
- public GameObject block;
- public Material mat_blue;
- public Material mat_red;
- // Use this for initialization
- void Start () {
- Screen.showCursor = false;
- }
- // Update is called once per frame
- void Update () {
- Ray ray = Camera.mainCamera.ScreenPointToRay(new Vector3(Screen.width/2,Screen.height/2,0));
- RaycastHit hit;
- if(Physics.Raycast(ray,out hit,5f) && hit.collider.tag == "Block")
- {
- if(Input.GetMouseButtonUp(0))
- {
- Vector3 pos = hit.collider.transform.position;
- pos += hit.normal;
- Instantiate(block,pos,Quaternion.identity);
- }
- else if(Input.GetMouseButtonUp(1))
- {
- DestroyObject(hit.collider.gameObject);
- }
- }else if(Physics.Raycast(ray,out hit,5f) && hit.collider.name == "Plane")
- {
- if(Input.GetMouseButtonUp(0))
- {
- Vector3 pos = hit.point;
- pos.y = 0;
- pos.x = Mathf.Round(pos.x);
- pos.z = Mathf.Round(pos.z);
- Instantiate(block,pos,Quaternion.identity);
- }
- }
- }
- void OnGUI()
- {
- if(Input.GetKey(KeyCode.M))
- {
- Screen.showCursor = true;
- GUILayout.BeginVertical();
- GUILayout.Label(block.renderer.sharedMaterial.name + "");
- if(GUILayout.Button("Blue"))
- {
- block.renderer.sharedMaterial = mat_blue;
- }
- if(GUILayout.Button("Red"))
- {
- block.renderer.sharedMaterial = mat_red;
- }
- GUILayout.EndVertical();
- }
- else
- {
- Screen.showCursor = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment