简体   繁体   中英

How to I add and delete objects from an AR scene using unity ARKit

I need to create an a furniture dropping app. While I have managed to figure out how to rotate scale the object and detect planes in AR world, I also need to enable the users to be able to choose from a list of furniture, add multiple furniture into the scene and also delete them as when they like. I can't seem to find any tutorials that teach this. There are plenty with ViewAR and Vuforia but since it is a school project, I am restricted to using the ARKit plugin in Unity. Any help in this would be highly appreciated!

So currently what I am doing is, I create an empty gameObject to which I attach a script that has the function call AddObject which is as such:

public void AddObject()
{

    GameObject summonedFurni = Instantiate(prefab);

    summonedFurni.transform.position = new Vector3 (0f, 0f, 0f);

    summonedFurni.transform.localScale = new Vector3 (10f, 10f, 10f);

    summonedFurni.AddComponent<Rigidbody> ();

    furniList.Add (summonedFurni);

    //summonedFurni.SetActive (true);

}

Each type of furniture is a separate gameObject to which the script is attached to. However, firstly the instantiated objects can't detect the plane and fall right through it. Adding a BoxCollider component simply causes all the furniture to stack up above me in the real world. Also I am unable to delete any objects from the scene as I am unable to keep track of the created objects. Any advice on this?

Adding a BoxCollider component simply causes all the furniture to stack up above me in the real world.

Try adding z position. By default z is 0. Which is your position as well. That's why it is stacking up above you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM