Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unable to Detect and/or Point Tally count using Unity 5 Beta.

Discussion in 'Immediate Mode GUI (IMGUI)' started by AlphaDraconis_SJ-ATX, Oct 25, 2014.

  1. AlphaDraconis_SJ-ATX

    AlphaDraconis_SJ-ATX

    Joined:
    Oct 25, 2014
    Posts:
    5
    I have the following:



    Assume I am a butterfly and I am roaming around any given scene -- Upon collision I send a tally count to 2 different Text "Label" instances... GUI template -- I have two different kinds of flowers:

    Code (CSharp):
    1.  
    2.  
    3. //public label object ** new!!
    4.  
    5. public Text dahliaTokenLabel;
    6.  
    7. public Text orchidTokenLabel;
    8.  
    9. // init both to 0 by default.
    10.  
    11. private uint dahliaTokens = 0;
    12.  
    13. private uint orchidTokens = 0;
    14.  
    15. //Here's the chunk that puzzles me. I evaluate a traditional OTE2D on a a simple 2D coll.
    16.  
    17. void OnTriggerEnter2D(Collider2D flowerCollider)
    18.  
    19.     {
    20.         //The main 'player' instance senses each "flower" token collider (is-trigger) and sets-up the  flower tally.
    21.    
    22.         //Tag-Comparison token collission.
    23.    
    24.         if (flowerCollider.gameObject.CompareTag("dahlias")) {
    25.    
    26.             CollectDahliaTokens(flowerCollider);
    27.    
    28.         }
    29.         else if (flowerCollider.gameObject.CompareTag("orchids")) {
    30.    
    31.    
    32.             CollectOrchidTokens(flowerCollider);
    33.         }
    34.    
    35.         //if all else fails...the butterfly stumbles upon a liar
    36.    
    37.         SwallowedByLizard(flowerCollider);
    38.  
    39.        
    40.     }
    41.  
    So the butterfly is able to move around the scene but it fails to acknowledge which is which, much less send the tally to the new GUI table.

    Code (CSharp):
    1. void CollectDahliaTokens(Collider2D dahliaCollider)
    2.     {
    3.         //up the tally
    4.         dahliaTokens++;
    5.    
    6.         //destroy -- maybe i shouldn't...same with the next block.
    7.         Destroy(dahliaCollider.gameObject);
    8.  
    9.         //...do something
    10.    
    11.    
    12.         //here
    13.         dahliaTokenLabel.text =dahliaTokens.ToString();
    14.     }
    15.  
    16.     void CollectDodecatokens(Collider2D orchidTokenCollider) {
    17.    
    18.         //+1
    19.        orchidTokens++;
    20.    
    21.         //...hmmm
    22.         Destroy(orchidTokenCollider.gameObject);
    23.    
    24.         //do something
    25.    
    26.         //point, or pass, the instance to the label object
    27.  
    28.         orchidTokenLabel.text = orchidTokens.ToString();
    29.    
    30.    
    31.     }
    32.  
    The butterfly flies over the flowers, collision is not detected, but interestingly enough, it DOES recognize the Lizard Collider. It does gets "swallowed by the lizard."

    hmmmm.....
     
    Last edited: Oct 26, 2014
  2. AlphaDraconis_SJ-ATX

    AlphaDraconis_SJ-ATX

    Joined:
    Oct 25, 2014
    Posts:
    5