Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GroundMakeCube : MonoBehaviour{
- private void Update() {
- if (Input.GetKeyDown(KeyCode.Space)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit)) {
- Vector3 pos = hit.point;
- pos.y = 0f;
- GameObject pref = Resources.Load("Prefabs/Cube") as GameObject;
- GameObject cubeNew=Instantiate(pref);
- cubeNew.GetComponent<Renderer>().material.color =
- UnityEngine.Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
- cubeNew.transform.position = pos;
- }
- }
- }
- }
- public class GroundMoveCube : MonoBehaviour {
- private Vector3 clickPos;
- public GameObject obj;
- private void Update() {
- if (Input.GetMouseButton(0)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- int layerMask = LayerMask.GetMask("Ground");
- if (obj!=null) {
- if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) {
- clickPos = hit.point;
- }
- clickPos.y = 0f;
- obj.transform.position = clickPos;
- Debug.Log("MOVE"+clickPos);
- }
- }
- if (Input.GetMouseButtonUp(0)) {
- obj = null;
- }
- }
- }
- public class SelectCube : MonoBehaviour {
- private void Update() {
- if (Input.GetMouseButtonDown(0)) {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- int layerMask = LayerMask.GetMask("Object");
- if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) {
- Debug.Log("Select"+hit.transform.name+" "+hit.transform.GetInstanceID());
- GameObject.Find("Main Camera").GetComponent<GroundMoveCube>().obj =
- hit.transform.gameObject;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement