Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TileDrawer : MonoBehaviour {
- public GameObject prefab;
- public Vector2 gridSize;
- // Use this for initialization
- void Start () {
- for(int x = 0; x < gridSize.x; x++) {
- for(int y = 0; y < gridSize.y; y++) {
- //GameObject go = (GameObject)Instantiate(prefab);
- GameObject go = new GameObject();
- go.transform.position = new Vector3(x,0,y);
- go.tag = "Grid";
- go.name = "Grid";
- BoxCollider col = go.AddComponent<BoxCollider>();
- col.isTrigger = true;
- }
- }
- }
- // Update is called once per frame
- void Update () {
- if(Input.GetMouseButton(0)) {
- CreateTile();
- }
- }
- void OnDrawGizmos() {
- for(int x = 0; x < gridSize.x; x++) {
- for(int y = 0; y < gridSize.y; y++) {
- for(int z = 0; z < 10; z++) {
- Gizmos.DrawWireCube(new Vector3(x,z,y), Vector3.one);
- }
- }
- }
- }
- void CreateTile() {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if(Physics.Raycast(ray, out hit)) {
- if(hit.collider.gameObject.tag == "Grid") {
- Vector3 pos = hit.collider.transform.position;
- GameObject go = (GameObject)Instantiate(prefab);
- go.transform.position = new Vector3(pos.x, pos.y, pos.z);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement