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

Rechange gameObject Tag

Discussion in 'Scripting' started by wolkeger, Feb 4, 2016.

  1. wolkeger

    wolkeger

    Joined:
    Jan 31, 2016
    Posts:
    8
    This code already exists;

    1) an Object reaches a Trigger
    2) OntriggerEnter
    2 a) a counter changes his state
    2b) the gameObjects` tag changes because the object shall trigger the counter only once

    Solutions (ideas)

    I press a special key and the game.objects` tag will return to the original state.

    I tried to use this function in void Update: but I do not know how to change the game Object again. In Void update the call "other.gameObject.tag ="specialtag" does not work.

    Here the code:

    Code (CSharp):
    1. public class csFileName : Monobehavior {
    2.  
    3. void OnTriggerEnter (Collider other)
    4. {
    5. if (other.gameObject.tag == "Ball")
    6. {
    7. other.gameObject.tag = "ball_deactivated";
    8. }
    9.  
    10. void update()
    11. {
    12. if (___SPECIAL_BUTTON_IS_PRESSED)
    13. {
    14.  
    15. !!--> Here Solution: Change objects` tag to "Ball" again
    16. }
    17. }
    18. }
    19.  
    Please show me how this could work.
    I definitely need a player controlled version of tag changing. OnTriggerExit versions won´t help, because the ball may hit the object more than once. I want to avoid that the counter changes his state uncontrolled.
     
    Last edited: Feb 4, 2016
  2. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
  3. wolkeger

    wolkeger

    Joined:
    Jan 31, 2016
    Posts:
    8
    New
    Tags were already defined in the tag manager.Thank you.
     
  4. MagicZelda

    MagicZelda

    Joined:
    May 1, 2013
    Posts:
    90
    you have OntriggerEnter and not OnTriggerEnter, in the original posted code. If that helps
     
  5. wolkeger

    wolkeger

    Joined:
    Jan 31, 2016
    Posts:
    8
    Please read the thread. It is about Problem solving and not such helpless hints like yours. Thank you.
     
  6. MagicZelda

    MagicZelda

    Joined:
    May 1, 2013
    Posts:
    90
    As you put it so nicely i will keep my Helpless hints to myself. Good luck with your problem.
     
  7. wolkeger

    wolkeger

    Joined:
    Jan 31, 2016
    Posts:
    8
    Sorry, I am done. I am writing on a huge project every day. So, I am little bit sensitive for hints like these.
     
  8. Juan_Soto

    Juan_Soto

    Joined:
    Nov 1, 2022
    Posts:
    4
    I don't know if you solved it, but the snippet you shared solved my one specific problem. I'm starting on Unity and this is crutial for a proyect that I'm doing, thank you so much.