Search Unity

Tag not working

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

  1. Penitent1

    Penitent1

    Joined:
    Oct 5, 2018
    Posts:
    51
    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. Vryken

    Vryken

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

    Penitent1

    Joined:
    Oct 5, 2018
    Posts:
    51
    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