|
@@ -26,18 +26,10 @@ public class BlockSpawner : MonoBehaviour
|
26
|
26
|
|
27
|
27
|
private bool _isPreview = false;
|
28
|
28
|
|
29
|
|
-
|
30
|
|
- public void Update()
|
31
|
|
- {
|
32
|
|
- if (_blockInstance == null) return;
|
33
|
|
-
|
34
|
|
- _blockInstance.transform.position = transform.position + transform.forward * spawnDistance;
|
35
|
|
- _blockInstance.transform.rotation = transform.rotation;
|
36
|
|
- }
|
37
|
|
-
|
38
|
29
|
public void OnPlaceBlock()
|
39
|
30
|
{
|
40
|
31
|
if (!_isPreview) return;
|
|
32
|
+ _blockInstance.transform.SetParent(null);
|
41
|
33
|
_blockInstance = null;
|
42
|
34
|
DisablePreviewMode();
|
43
|
35
|
}
|
|
@@ -54,16 +46,15 @@ public class BlockSpawner : MonoBehaviour
|
54
|
46
|
{
|
55
|
47
|
if (_blockToPlace == null) return;
|
56
|
48
|
|
57
|
|
- Vector3 pos = transform.position + transform.forward * spawnDistance;
|
58
|
|
- Quaternion rot = transform.rotation;
|
59
|
|
- _blockInstance = Instantiate(_blockToPlace, pos, rot);
|
|
49
|
+ Vector3 spawnPos = Vector3.forward * spawnDistance;
|
|
50
|
+ _blockInstance = Instantiate(_blockToPlace, spawnPos, Quaternion.identity);
|
|
51
|
+ _blockInstance.transform.SetParent(this.transform, false);
|
60
|
52
|
_isPreview = true;
|
61
|
53
|
}
|
62
|
54
|
|
63
|
55
|
private void DisablePreviewMode()
|
64
|
56
|
{
|
65
|
|
- Destroy(_blockInstance);
|
66
|
|
- Debug.Log("disabled");
|
|
57
|
+ if (_blockInstance != null) Destroy(_blockInstance);
|
67
|
58
|
_isPreview = false;
|
68
|
59
|
}
|
69
|
60
|
}
|