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 /
avatar image
0
Question by Sanjay1987 · Aug 24, 2018 at 11:16 AM · prefab

Rotating specific prefab - instantiated with Random.Range

I have instantiated my Prefabs using Random.Range.(different types of prefabs) Out of the different instantiated prefabs i want to rotate a specific prefab.

Any help would be appreciated..Thank you

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

Answer by RustyCrow · Aug 24, 2018 at 11:30 AM

Not coding atm but assuming a small range(0 - 2)

Edit: replacing with actual code and a better explanation. So reading your response @Sanjay1987 i think you are just Rotating on wrong angle, try Y for horizontal, X will make like a ramp and Z is a barrel role :P idk. But for the code (keep in mind i dont know your code setup/structure so this might not work for you) I also might have misunderstood your question in case you want to do operations after spawn see the comments in the code.

     void Start ()
     {
         for (int i = 0; i < Prefabs.Length; i++)
         {
             var result = Random.Range(0,2); // This is ouer prefab value
             // Alt ver if you want to spawn first Then do change
             // var go = insta(pref[res])
 
             // we determin ouer Prefab(in this case i want the prefab at index 1 to be tilted)
             if (result == 1 ) 
             {
                 // angle the prefab on index 1
                 Instantiate(Prefabs[result], transform.position, Quaternion.Euler(new Vector3(0, 45, 0))); 
                 //go.trans.rot = Quaternion.Euler(new Vector3(0, 45, 0))
             }
             else
             {
                 Instantiate(Prefabs[result], transform.position, Quaternion.identity);
                 // go.trans.rot =  Quaternion.identity
             }
         }
     }

The assumption here is that you are using Random value in a Array to determine which prefab to spawn. If we now save that number and say if this value shows up then do something els with the Gameobject(like rotating it) else just do a standard spawn. This is a very basic answer if you need more complex one i think we need to see your script(s).

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 eses · Aug 24, 2018 at 11:37 AM 1
Share

How would this address "i want to rotate a specific prefab." after instantiating the prefabs part, as it seems like he wants to do this after the instantiation.

avatar image RustyCrow eses · Aug 24, 2018 at 03:04 PM 0
Share

Hmm i must be misunderstanding the question then. The specific prefab would be the value you would put in the if statement(over case 1) then do the rotation with instantiate parameter or i guess do it after instantiating

 var go = insta(prefab)
 go.trans.rotation = new rotation
avatar image
0

Answer by Sanjay1987 · Aug 24, 2018 at 11:41 AM

@RustyCrow Thank you. I did the exact same thing. But instead the object won't rotate along the x-axis.(like when you collect coins, coins rotate horizontally). Sorry if this tends to become a new topic. After finding the specific instance using the above method. i wrote this.

 Instantiate (prefabs[result, newTransform.position, Quaternion.Euler (45, 0, 0));

But this just slants the prefab instead of rotating it.

Anyway thanks for you help.

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 RustyCrow · Aug 24, 2018 at 03:48 PM 0
Share

Try changing the value on Y (0,45,0) (X, Y, Z), if still not working check out the updated answer

avatar image Sanjay1987 RustyCrow · Aug 30, 2018 at 12:06 PM 0
Share

@RustyCrow Thank you very much.. Sorry if this is a lame question. I have set my project in 2d mode. When i switch it to 3d i can see the prefab rotating on all axes. But when i switch back to 2d, the 3d effect disappears. So has it got to do anything with my project settings. Or could i get a 3d effect in a 2d project?

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

Photon Instantiated Prefab of OTHER Player Falls Over 1 Answer

nee help with Instantiating prefab at mouse position with GUI button 0 Answers

How do you spawn multiple prefabs within a certain distance from each other from one spawn point? 2 Answers

Accessing Script on instated prefab 1 Answer

Assign a 'Transform' target to prefab by finding a 'GameObject' 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