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
1
Question by Reshad · Jun 20, 2013 at 08:11 AM · level design

How to create a loop level?

Hi guys, I want to randomly instantiate a prefab under a particular game object with specific rotation. For more details I have 12 level prefabs on a circle segment model. I want to instantiate these prefabs randomly with rotation 0, 90(y-axis), 180(y-axis), 270(y-axis) when player touches a trigger. So the entire level will change the prefabs clockwise and a loop will be created. But I don't know how exactly I can do it. Any help will be much 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
Best Answer

Answer by Reshad · Jun 24, 2013 at 05:52 AM

Finally I got it working. I have placed four trigger on the road end position and instantiated prefab randomly when player touches the trigger and destroy the previous one. For that a loop circle level has been created what I wanted.

 using UnityEngine;
 using System.Collections;
 
 public class LevelChange : MonoBehaviour {
 
     public int randomChange;
     
     private int startLevel = 0;
     private int endLevel = 11;
     public Transform s1;
     public Transform s2;
     public Transform s3;
     public Transform s4;
     
     public GameObject[] level_prefab = new GameObject[12];
     
     
     void Start() {
         
 NotificationCenter.DefaultCenter.AddObserver(this, "TriggerA");
         NotificationCenter.DefaultCenter.AddObserver(this, "TriggerB");
         NotificationCenter.DefaultCenter.AddObserver(this, "TriggerC");
         NotificationCenter.DefaultCenter.AddObserver(this, "TriggerD");
         
         s1 = GameObject.Find("S1").transform; //0-degree
         s2 = GameObject.Find("S2").transform; //90-degree
         s3 = GameObject.Find("S3").transform; //180-degree
         s4 = GameObject.Find("S4").transform; //270-degree
         
         GameObject l1 = Instantiate(level_prefab[startLevel], s1.transform.position, s1.transform.rotation) as GameObject;
         l1.transform.parent = s1.transform;
         
         GameObject l4 = Instantiate(level_prefab[endLevel], s4.transform.position, s4.transform.rotation) as GameObject;
         l4.transform.parent = s4.transform;
     }
     
     void Update() {
         
         randomChange = Random.Range(0,12);
         //Debug.Log(randomChange);
     }
     
     public void TriggerA() {
         
         GameObject l2 = Instantiate(level_prefab[randomChange], s2.transform.position, s2.transform.rotation) as GameObject;
         l2.transform.parent = s2.transform;
         
         foreach(Transform child in s4) {
                 
             Destroy(child.gameObject);
         }
     }
     
     public void TriggerB() {
         
         GameObject l3 = Instantiate(level_prefab[randomChange], s3.transform.position, s3.transform.rotation) as GameObject;
         l3.transform.parent = s3.transform;
         
         foreach(Transform child in s1) {
                 
             Destroy(child.gameObject);
         }
         
     }
     
     public void TriggerC() {
         
         GameObject l4 = Instantiate(level_prefab[randomChange], s4.transform.position, s4.transform.rotation) as GameObject;
         l4.transform.parent = s4.transform;
         
         foreach(Transform child in s2) {
                 
             Destroy(child.gameObject);
         }
         
         
     }
     
     public void TriggerD() {
         
         GameObject l1 = Instantiate(level_prefab[randomChange], s1.transform.position, s1.transform.rotation) as GameObject;
         l1.transform.parent = s1.transform;
         
         foreach(Transform child in s3) {
                 
             Destroy(child.gameObject);
         }
         
     }     
         
 }
 
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
1

Answer by AlucardJay · Jun 20, 2013 at 08:13 AM

 // when the player hits the trigger
 
 var rot : Quaternion;
 
 switch( Random.Range( 0, 4 ) )
 {
     case 0 :
         rot = Quaternion.Euler( 0, 0, 0 );
     break;
     
     case 1 :
         rot = Quaternion.Euler( 0, 90, 0 );
     break;
     
     case 2 :
         rot = Quaternion.Euler( 0, 180, 0 );
     break;
     
     case 3 :
         rot = Quaternion.Euler( 0, 270, 0 );
     break;
 }
 
 object.rotation = rot;
Comment
Add comment · Show 3 · 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 Reshad · Jun 20, 2013 at 09:29 AM 0
Share

Thank you for your answer. But when I use rot = Quaternion.Euler( 0, 90, 0 ); my editor y-axis rotation value shows 90.00001. How can I solve it? I can't find any exact solution for that.

avatar image Reshad · Jun 20, 2013 at 09:46 AM 0
Share

I have a arc model of a circle and I want to load it from my resource and at the end of the arc I set a trigger. When the player touches that trigger I want to instantiate that model again with different rotation and join the vertex of that model with previous model. Can anyone tell me how to join the second model's vertex with the first model in coding? alt text

problem.jpg (51.8 kB)
avatar image AlucardJay · Jun 24, 2013 at 05:51 AM 0
Share

Wow, sorry, I never received a reply email until now. It looks like Unity Answers email notification has not been working again. (the 'site was down for maintenance twice this weekend)

Am glad you got the problem solved. You get upvote from me for your persistence!

Regarding the floating point error, I cannot explain that. Unity is strange sometimes when it comes to euler rotations.

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

15 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

Related Questions

World building advice for 3.5D platformer 0 Answers

Stacking level blocks in an Infinite runner game 2 Answers

How much of a video game's art is made in the engine and how much from external programs? 1 Answer

Using custom Transform/GameObject classes? 0 Answers

Model in Blender, or Block in Unity? 0 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