Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. 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:
    22
    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:
    380
    Is the object's tag exactly named "Boomstick"?
     
  3. matthewsingerjealouz

    matthewsingerjealouz

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