Browse Source

Fix

Le bloc de preview ne saccade plus
shader
Figg 4 years ago
parent
commit
0879aeb52a
2 changed files with 6 additions and 15 deletions
  1. 5
    14
      FreeCam/Assets/BlockSpawner.cs
  2. 1
    1
      FreeCam/Assets/Scenes/SampleScene.unity

+ 5
- 14
FreeCam/Assets/BlockSpawner.cs View File

26
 
26
 
27
     private bool _isPreview = false;
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
     public void OnPlaceBlock()
29
     public void OnPlaceBlock()
39
     {
30
     {
40
         if (!_isPreview) return;
31
         if (!_isPreview) return;
32
+        _blockInstance.transform.SetParent(null);
41
         _blockInstance = null;
33
         _blockInstance = null;
42
         DisablePreviewMode();
34
         DisablePreviewMode();
43
     }
35
     }
54
     {
46
     {
55
         if (_blockToPlace == null) return;
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
         _isPreview = true;
52
         _isPreview = true;
61
     }
53
     }
62
 
54
 
63
     private void DisablePreviewMode()
55
     private void DisablePreviewMode()
64
     {
56
     {
65
-        Destroy(_blockInstance);
66
-        Debug.Log("disabled");
57
+        if (_blockInstance != null) Destroy(_blockInstance);
67
         _isPreview = false;
58
         _isPreview = false;
68
     }
59
     }
69
 }
60
 }

+ 1
- 1
FreeCam/Assets/Scenes/SampleScene.unity View File

687
     - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
687
     - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
688
       propertyPath: _blockToPlace
688
       propertyPath: _blockToPlace
689
       value: 
689
       value: 
690
-      objectReference: {fileID: 0}
690
+      objectReference: {fileID: 3300812737117657924, guid: 7b30a4c90d614f747872471cf43b8e56, type: 3}
691
     m_RemovedComponents: []
691
     m_RemovedComponents: []
692
   m_SourcePrefab: {fileID: 100100000, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
692
   m_SourcePrefab: {fileID: 100100000, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}

Loading…
Cancel
Save