Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by leochan0102 · Apr 01, 2015 at 04:38 PM · 3dobjectrotatevuforia

How to transform different 3d object with button

I am using vuforia and I have some problem with transform different 3d object with button I used the code TargetTransformer but it only can transform one specific object. However this code only can control one object,I know that if I need to control other object I can copy one more and change my object name. But it will become more button on the screen. I want to use the same button to scale, rotate my 3 objects

the code is this https://developer.vuforia.com/forum/faq/unity-how-can-i-transform-teapot

Comment
Add comment · Show 2
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 lordlycastle · Apr 01, 2015 at 05:26 PM 0
Share

No one’s gonna read through all that. Post at most 10 lines of code, then if people ask for more supply more.

avatar image leochan0102 · Apr 03, 2015 at 02:43 AM 0
Share

the sample code

https://developer.vuforia.com/forum/faq/unity-how-can-i-transform-$$anonymous$$pot

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by KdRWaylander · Apr 03, 2015 at 06:54 AM

Say you want to change that function:

  if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
         {
             float oldScale = mTeapotTransform.localScale.x;
             float newScale = oldScale * 1.5f;
             mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
         }

You can see that the 2 first lines are about changing the scale, so you don't need to touch that (unless you want a different scale for each object). Third (and last) line is about localScale so it is here that you change the scale of your object, you will hence want to copy that line as many times as objects you want to modify. Say you want to change 3 objects the code will look like that now:

 if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
         {
             float oldScale = mTeapotTransform.localScale.x;
             float newScale = oldScale * 1.5f;
             mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
             mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
             mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
         }

But obviously since we only copy and pasted a line it won't change an OTHER object, it will affect the same, so we have to change the name of the object that is called. Let's say these 2 new objects are A and B, we now have:

  if (GUI.Button(new Rect(50,0,140,70), "Scale Up"))
         {
             float oldScale = mTeapotTransform.localScale.x;
             float newScale = oldScale * 1.5f;
             mTeapotTransform.localScale = new Vector3(newScale, newScale, newScale);
             A.localScale = new Vector3(newScale, newScale, newScale);
             B.localScale = new Vector3(newScale, newScale, newScale);
         }

But now we have to tell the script who the hell A et B are (because right it's wondering), so let's go back to the start of the script where we can declare these gameobjects:

 private Transform mTeapotTransform = null;

Let's add our lines:

 private Transform mTeapotTransform = null;
 private Transform A = null;
 private Transform B = null;

We are now very close, the script knows who are A and B but don't know to which gameobject link them (since null means nothing), the start function is here for us (i put directly modified):

  // Use this for initialization
     void Start ()
     {
         GameObject teapot = GameObject.Find("teapot");
         if (teapot != null)
         {
             Debug.Log("Teapot found");
             mTeapotTransform = teapot.transform;
         }
 
 GameObject whateverObjectInMyScene1 = GameObject.Find("whateverObjectInMyScene1");
         if (whateverObjectInMyScene1 != null)
         {
             Debug.Log("whateverObjectInMyScene1 found");
             A = whateverObjectInMyScene1.transform;
         }
 
 GameObject whateverObjectInMyScene2 = GameObject.Find("whateverObjectInMyScene2");
         if (whateverObjectInMyScene2 != null)
         {
             Debug.Log("whateverObjectInMyScene2 found");
             B = whateverObjectInMyScene2.transform;
         }
     }

And that's it ! Now that you have those new variables you can change the other buttons too, shouldn't be very difficult :)

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 leochan0102 · Apr 04, 2015 at 03:45 PM 0
Share

thankyou very much , it seems not difficult, i am new in unity and code it is a simple to solve it!

avatar image KdRWaylander · Apr 10, 2015 at 06:42 AM 0
Share

if it's all good for you, mark the question as answered so people with same difficulties can take benefits of it :)

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

2 People are following this question.

avatar image avatar image

Related Questions

Make object visible in dark 2 Answers

3d object on GUI 1 Answer

How to make a drag and drop menu in 2d for a 3d game (sims 4 furniture like) 0 Answers

I try to move my 3D object in the game but it only on the X & Z axis, can someone help me with that 1 Answer

How to add texture to Blender objects properly? 2 Answers


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