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 GKdev1980 · Apr 03, 2014 at 10:35 AM · triggerboxcollider2d

Title letters appearing one after another

I want to set some objects inactive when my scene starts and I want to enable them consequently after some time (basically it's a title and I want each letter to appear a few milliseconds after the previous one).

I've made each letter a separate GameObject, since I want to rotate them too. I suppose there is the "wrong" way of attaching a single script to each letter individually and setting a timer to each script.

I thought of doing it more "correctly", by adding BoxCollider2D components to each letter and having an empty GameObject with a BoxCollider2D moving through my screen, enabling each letter one at a time.

My Start method is

 void Start () {
 
         GameObject[] titleElements = GameObject.FindGameObjectsWithTag ("Title");
 
         foreach (GameObject titleElement in titleElements)
                 titleElement.SetActive(false);
     }

and it works fine, since I've tagged each of my letters as "Title", when I start my scene all these objects get deactivated.

In the Update method I move my empty "trigger" object horizontally in my scene, all of my objects have collider2D components with "isTrigger" enabled and my trigger object also has a RigidBody2D component. I had followed some tutorial on how to make a 2D game (clonybird if anyone is familiar) and it turns that I have to set my RigidBody2D Gravity to 0 and disable isKinematic or else my trigger object won't collide with the other colliders.

But my letters don't seem to collide with my trigger. Maybe this has to do with the fact that they are children to a camera which is a part of an NGUI-based GUI and I'm not 100% familiar with the way this works yet, I use it to have a resolution-independent UI.

I created an empty Game object with a BoxCollider2D object to test my logic and now my trigger triggers both this empty GameObject and a single Gameobject of my title, which is not the first it collides to. I really cannot understand what is happening.

I know it's a very long post, but if anyone makes anything out of it I would be grateful..

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 VesuvianPrime · Apr 03, 2014 at 10:44 AM 0
Share

I'd argue attaching a script to each letter is a perfectly fine approach.

If I were to approach this problem I would write a single $$anonymous$$onoBehaviour that has reference to all of the letters via an array field.

This $$anonymous$$onoBehaviour would then randomly begin the animation of each letter over a fixed period of time.

avatar image GKdev1980 · Apr 03, 2014 at 11:43 AM 0
Share

I think I did some of that in my start method

 GameObject[] titleElements = GameObject.FindGameObjectsWithTag ("Title");

The problem is that they are in random order inside the array.

I temporarily solved my problem by adding separate empty GameObjects with colliders and manually activating each object (in the right order) when my trigger object collides with these.

I know this is not the right way to code, but at least it works.

I still can't understand why it doesn't collide with the colliders of the letter objects within NGUI ui..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Apr 03, 2014 at 10:50 AM

Why wouldn't you use an easy GUI.Box?

 string title = "My Game";
 string str = "";
 public float freq = 1.0f;
 void Start(){
    StartCoroutine(AddLetter());
 }
 void OnGUI(){
    GUI.Box(rect, str);
 }
 
 IEnumerator AddLetter()
 {
     float timer = 0f;
     int index = 0;
     while(index < title.Length){
         while(timer < freq){ // freq defines how fast letters show up
              timer += Time.deltaTime;
              yield return null;
         }
         str += title[index];
         index++;
         timer = 0;
     }
 }
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 GKdev1980 · Apr 03, 2014 at 11:14 AM 0
Share

I've read a few comments advising to stay away from OnGUI, so I thought of using NGUI, to ensure easiest resolution-independent UI.

I will look through your code though to check the logic, thanks...

avatar image fafase · Apr 03, 2014 at 12:54 PM 0
Share

Yes, you should avoid GUI mostly for in game GUI. But if you have a situation with little happening like a front page menu, GUI is fine to my taste. And GUI will slow down if you abuse it on a slow computer or if you have tens of indicator on a mobile game.

I have yet to experience any problem using GUI.

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

21 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

Related Questions

Why is this only working for the second object that collides? 1 Answer

Can't click gameobject when over another trigger? 1 Answer

Box Collider 2D "Is Trigger" Help! 1 Answer

How to get box collider detection by Ray cast only from the outside of the box collider 1 Answer

BoxCollider2D, Trigger not working 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