Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Tag not working

Discussion in 'Scripting' started by matthewsingerjealouz, Oct 14, 2018.

  1. matthewsingerjealouz

    matthewsingerjealouz

    Joined:
    Oct 5, 2018
    Posts:
    26
    This script is on my player, it detects a tag for the shotgun.
    Some reason when my player collides with the tag it does not set to true ?
    Any help would be appreciated, thank you.

    Code (CSharp):
    1. public class Shotgun : MonoBehaviour {
    2.     Animator animator;
    3.     public bool shotgun;
    4.  
    5.  
    6.     void Start () {
    7.         animator = GetComponent<Animator> ();
    8.         //animator.SetBool ("Shotgun", true);
    9.     }
    10.  
    11.  
    12.     void OnTriggerEnter2D(Collider2D other)
    13.     {
    14.         if (other.tag == "Boomstick")
    15.         {
    16.             animator.SetBool ("Shotgun", true);
    17.         }
    18.     }
    19. }
     
  2. Cucci_A

    Cucci_A

    Joined:
    Jan 23, 2018
    Posts:
    413
    Is the object's tag exactly named "Boomstick"?
     
  3. matthewsingerjealouz

    matthewsingerjealouz

    Joined:
    Oct 5, 2018
    Posts:
    26
    My bad i did not look in animator while running my game.
    It`s setting the bool to true, but sends my Walk animation in a constant loop o_0
    Any ideas what i should do.

    *Update. In my walk cycle i had shotgun false when walking.
    I deleted them, now it works. fine. Sorry