Skip to content

Commit 559cb0d

Browse files
committed
Improved logic of placing objects.
1 parent 27c815b commit 559cb0d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Scripts/ARPlaceObjectOnPlane.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information.
22

33
using System;
4+
using System.Collections.Generic;
45
using UnityEngine;
56
using UnityEngine.Events;
67
using UnityEngine.XR.ARFoundation;
@@ -30,6 +31,8 @@ public class ARPlaceObjectOnPlane : MonoBehaviour
3031

3132
public GameObjectPlacedEvent GameObjectPlaced;
3233

34+
public List<GameObject> objectsPlaced = new List<GameObject>();
35+
3336
public Camera mainCamera { get; private set; }
3437

3538
private bool _objectToPlaceActiveState;
@@ -46,7 +49,12 @@ public void PlaceObjectOnPlane(Pose pose, ARPlane plane)
4649

4750
var objectToPlaceGameObject = objectToPlace;
4851

49-
if (placeMultiple)
52+
if (!placeMultiple && objectsPlaced.Count != 0)
53+
{
54+
return;
55+
}
56+
57+
if (!objectToPlaceGameObject.scene.IsValid())
5058
{
5159

5260
objectToPlaceGameObject = Instantiate(objectToPlace);
@@ -73,6 +81,8 @@ public void PlaceObjectOnPlane(Pose pose, ARPlane plane)
7381
cameraPosition.z
7482
));
7583

84+
objectsPlaced.Add(objectToPlaceGameObject);
85+
7686
GameObjectPlaced?.Invoke(objectToPlaceGameObject);
7787

7888
}

0 commit comments

Comments
 (0)