-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreator.cs
More file actions
118 lines (95 loc) · 2.52 KB
/
Creator.cs
File metadata and controls
118 lines (95 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Creator : MonoBehaviour
{
public GameObject Plano;
public List<GameObject> Planos;
// = new List<GameObject> ()
public GameObject avatar;
public Vector3 altePos;
Vector3 sqBounds;
// Use this for initialization
void Start ()
{
sqBounds = Plano.transform.GetComponent<MeshFilter> ().sharedMesh.bounds.size;
// StartCoroutine ("CreatePlanos", Vector3.zero);
CreatePlanos (transform.position);
}
void DeletePlanos ()
{
foreach (GameObject g in Planos) {
if (g.tag != "centro")
Destroy (g);
}
Planos.Clear ();
}
void CreatePlanos (Vector3 creationPos)
{
for (int z = -1; z < 2; z++) {
for (int x = -1; x < 2; x++) {
CreateFlat (z, x, creationPos);
}
}
}
void CreateFlat (int z, int x, Vector3 creationPos)
{
GameObject p = Instantiate (Plano) as GameObject;
p.transform.position = new Vector3 (creationPos.x + p.transform.localScale.x + x * sqBounds.x,
creationPos.y,
creationPos.z + p.transform.localScale.z + z * sqBounds.z);
p.name = " p. x " + x + "p. y " + z;
if (x == 0 && z == 0) {
p.tag = "centro";
}
Planos.Add (p);
}
void UpdateCentroPos ()
{
foreach (GameObject g in Planos) {
if (g.tag == "centro")
g.transform.position = transform.position;
}
}
void Renew (Vector3 creationPos)
{
for (int z = -1; z < 2; z++) {
for (int x = -1; x < 2; x++) {
CreateFlat (z, x, creationPos);
if (z != 0 && x != 0) {
// UpdateCentroPos ();
//
//
// GameObject p = Instantiate (Plano) as GameObject;
// p.transform.position = new Vector3 (creationPos.x + p.transform.localScale.x + x * sqBounds.x,
// creationPos.y,
// creationPos.z + p.transform.localScale.z + z * sqBounds.z);
// p.name = " p. x " + x + "p. y " + z;
// Planos.Add (p);
}
}
}
}
// Update is called once per frame
void Update ()
{
// if (Input.GetKey (KeyCode.F))
CheckPos ();
print (transform.position.x + " " + altePos.x + " " + sqBounds.x);
}
void CheckPos ()
{
if (transform.position.x > altePos.x + sqBounds.x / 2 || transform.position.x < altePos.x - sqBounds.x / 2) {
altePos = transform.position;
DeletePlanos ();
// CreatePlanos (transform.position);
Renew (transform.position);
}
if (transform.position.z > altePos.z + sqBounds.z / 2 || transform.position.z < altePos.z - sqBounds.z / 2) {
altePos = transform.position;
DeletePlanos ();
// CreatePlanos (transform.position);
Renew (transform.position);
}
}
}