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 Makiavel · Oct 25, 2012 at 11:03 PM · javascriptprefabrotategrid

Script is working incorrectly. (rotation)

I have a simple script, that places copies of a prefab object on the scene at a certain order.

To the prefab is attached the following script:

 var x:float = 0.0;
 var y:float = 90.0;
 
 function Start ()
 {
 var z:int;
 z=Random.Range(1.0, 4.0);  
 x=(y*z);  
 transform.Rotate(0.0, x, 0.0);
 print(x);
 }
 
 function Update () 
 {
 }


This script is supposed to turn the object by 90 degrees on y axis up to four times on start, in order to randomize the placement, but keeping the structure.

Problem is, when I launch the placement script, those prefabs that are turned are placed out of their place in structure.

Prefab consists of a three cubes, that are combined in an empty object.

Here is a placement script, just in case. It works fine by itself. It creates a grid of prefabs, placed in a square with a changeable distance between them and the size of a square itself.

 var Xvalue:float = 0.0;
 var Zvalue:float = 0.0;
 var ChangeCounter:int = 1.0;
 var ChangeAmount:float = 20.0;
 var Technical_Couter:int = 1.0;
 var PlayFieldSize:float = 0.0;
 var prefab1:Transform;
 var a:float=1.0;
 var b:float=1.0;
 

 function Update () 
 {
     if(ChangeCounter<PlayFieldSize)
         {
         Xvalue=(ChangeAmount*ChangeCounter);
         Instantiate (prefab1, Vector3(Xvalue, 0.0, 0.0), Quaternion.identity);
         print("Starting a new circle, placing first platform");
 
         //On the first circle x=0
         
     if(ChangeCounter>0)
     {
         while(Technical_Couter<(ChangeCounter+1))
             {
             Zvalue=(ChangeAmount*Technical_Couter);
             Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
             print("vertical row");
             print(a);
             a++;
             Technical_Couter++;
             }
         
         while(Xvalue>0)
         {
             Xvalue=(Xvalue-ChangeAmount);
             Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
             print("horizontal row");
             print(b);
             b++;
             
         }
     }
         
         a=1.0;
         b=1.0;
         ChangeCounter++;
         Technical_Couter=1.0;
         }
 }
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

1 Reply

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

Answer by hvilela · Oct 26, 2012 at 12:59 AM

Looks like you have a pivot problem. Drag your prefab to the scene and select the GameObject that are parent of the three cubes. Make sure your in "pivot mode".

alt text

The gizmo will indicates your object pivot, that represents his center. He'll rotate around this. Change your Y directly in the inspector to understand it better.


screen shot 2012-10-25 at 10.57.08 pm.png (7.4 kB)
Comment
Add comment · Show 1 · 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 Makiavel · Oct 26, 2012 at 09:34 AM 0
Share

Thank you, that was a very stupid mistake) I completely forgot about that setting.

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

10 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

Related Questions

rot not working for 2nd prefab 2 Answers

Random Script Failure 1 Answer

Can't add a script to a prefab script: JavaScript 1 Answer

Prefab Instancing 2 Answers

Prefabs and variables 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