Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    418
    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