Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ClickToPlaceBlock : MonoBehaviour {
- public GameObject cube;
- public GameObject cubeThingy;
- // Use this for initialization
- void Start() {
- }
- // Update is called once per frame
- void Update() {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit = new RaycastHit();
- if (Physics.Raycast(ray.origin, ray.direction, out hit, 50f)) {
- Debug.DrawRay(ray.origin, ray.direction, Color.green, 0.01f, true);
- float hitX = Mathf.Round(hit.point.x);
- float hitY = hit.transform.gameObject.transform.position.y + 1;
- float hitZ = Mathf.Round(hit.point.z);
- Debug.Log(hit.transform.name);
- cube.transform.position = new Vector3(hitX, hitY, hitZ) + ray.direction;
- if (Input.GetButtonDown("Fire1")) {
- GameObject go = Instantiate(cubeThingy, new Vector3(hitX, hitY, hitZ) + ray.direction, hit.transform.rotation) as GameObject;
- go.name = go.transform.position.ToString();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment