Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Gianluca90 · Jun 28, 2016 at 08:21 AM · androidunity 5modelbuttonsswapping

Swap 3D model with a button

Hello everybody! At first, sorry for my bad english. I'm working with unity 5.3.5 and Vuforia 5.5. Unfortunately i'm not able to write script then i'm in trouble!! I'm building an AR app for Android and i want to swap the 3d model with another 3d model when i press a GUI button. i've read in all forums but nothing work fine... someone can help me?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gianluca90 · Jul 01, 2016 at 09:58 AM

I solved my problem!I modified this script(https://www.ourtechart.com/augmented-reality/tutorial/augmented-reality-user-interface-unity3d/) adding features. This is the modified script:link text

@hyperi0n


script.txt (5.8 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by hyperi0n · Jun 28, 2016 at 09:59 AM

Hi! If I understood you correctly, the easiest way would be:

Create/Load both objects at the start of the program and deactivate one of them. Then create a button for each of your objects.

Select your button. In the inspector, under the section "On Click()" click the little "+" sign at the bottom. Drag your first object into the "Object" Slot. In the "Function"-drop down, select GameObject/SetActive(Bool). A little checkbox appears; leave it empty. Do the same thing again (click plus, drag the second object into the object-slot; select "GameObject/SetActive(Bool)" and this time, activate the checkbox.

This way, when you click the button, Object A gets deactivated and Object B gets activated. However, this will only work "one way", so you will need one button per possible object. If you want to toggle/switch between the objects multiple times using one button, you will have to write a little script. If you need help with that, don't hesitate to ask.

I hope this helped you a bit - good luck!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gianluca90 · Jun 28, 2016 at 01:48 PM 0
Share

Hi hyperi0n! your method is good :) But if i want to use a lot of 3d models i need a script. i'd like to know how i can change this models with back and forth buttons. Can you help me with a script?

avatar image hyperi0n Gianluca90 · Jun 28, 2016 at 01:55 PM 1
Share

Ok I would suggest the following: attach a script to your BUTTON, call it "CycleThroughObjectsScript" or something ;) Inside the script declare an array of game Objects as well as an int variable:

public var objects : GameObject[]; public var currentObject : int;

In the editor, drag all the possible objects from the hierarchy into the appropriate slot in the btton's inspector window under the script. Note, that only one of the objects should be active.

then in the Start function of the script, I would place something like

 for(var i : int = 0; i < objects.length; i++){
 if (objects[i].activeSelf){
 currentObject = i;
 }
 }

This is so that the script knows which object is currently being displayed. Then add a function to the script:

 function DisplayNextObject(){
 objects[i].SetActive(false);
 i++;
 if ( i > objects.length){
 i = 0;
 }
 objects[i].SetActive(true);
 }

One last thing left to do: In the editor, select the button, and in the inspector go to the bottom where it says "OnClick". ins$$anonymous$$d of the things we added there in my original reply, simply have one effect (click the "+" once) and do the following: drag the SCRIPT component into the "object" slot. Then, in the "function" dropdown, choose "CycleThroughObjectsScript" (or whatever you named the script) and select the "DisplayNextObject" function. If everything went well, this should allow you to cycle through the 3d models with 1 button :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

117 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

is device supported to cardboard game or not? 0 Answers

Unity plus and Android Pro 0 Answers

Android VR Application crashing without splash screen. 0 Answers

Android Status and Navigation bars appears in fullscreen after blocking the screen. 0 Answers

Firebase Offline Support? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges