Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Mouse drag cloning Game Objects

$
0
0
So I'm making a mario maker "clone" and I want it to instantiate objects when I hold control and drag. It makes almost infinite tiles. I want it to only make an object if the new position is the same as an old position of an object. Everything snaps to a grid of 1 by 1 blocks public GameObject tilePrefab; void OnMouseDrag(){ Vector2 pos = Input.mousePosition; pos = Camera.main.ScreenToWorldPoint (pos); pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); transform.position = pos; if (Input.GetKey (KeyCode.LeftControl)) { if (transform.position != GameObject.Find ("SomePrefabName").transform.position) { GameObject myGameObject = Instantiate (tilePrefab) as GameObject; myGameObject.name = "SomePrefabName"; } } } ![Before Drag][1]![After Drag][2] [1]: https://i.stack.imgur.com/uhBxx.pnghttp:// [2]: http://https://i.stack.imgur.com/UrNCO.png

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>