Guest User

Untitled

a guest
May 15th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ClickToPlaceBlock : MonoBehaviour {
  5.     public GameObject cube;
  6.     public GameObject cubeThingy;
  7.     // Use this for initialization
  8.     void Start() {
  9.  
  10.     }
  11.  
  12.     // Update is called once per frame
  13.     void Update() {
  14.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  15.  
  16.         RaycastHit hit = new RaycastHit();
  17.  
  18.         if (Physics.Raycast(ray.origin, ray.direction, out hit, 50f)) {
  19.             Debug.DrawRay(ray.origin, ray.direction, Color.green, 0.01f, true);
  20.             float hitX = Mathf.Round(hit.point.x);
  21.             float hitY = hit.transform.gameObject.transform.position.y + 1;
  22.             float hitZ = Mathf.Round(hit.point.z);
  23.             Debug.Log(hit.transform.name);
  24.             cube.transform.position = new Vector3(hitX, hitY, hitZ) + ray.direction;
  25.  
  26.  
  27.  
  28.             if (Input.GetButtonDown("Fire1")) {
  29.  
  30.                 GameObject go = Instantiate(cubeThingy, new Vector3(hitX, hitY, hitZ) + ray.direction, hit.transform.rotation) as GameObject;
  31.                 go.name = go.transform.position.ToString();
  32.  
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment