Search Unity

Can't setTrigger() for another GameObject

Discussion in 'Animation' started by xobookx, Jan 22, 2019.

  1. xobookx

    xobookx

    Joined:
    Jan 5, 2019
    Posts:
    3
    I have a Game Controller on a Game Controller object and I want to setTrigger(); on the players (another object) animator to trigger his animation. This doesn't work. The following is my code:
    Code (CSharp):
    1. public class buttonSwap : MonoBehaviour
    2. {
    3.     [SerializeField]
    4.     private GameObject player;
    5.     private Animator playerAnim;
    6.  
    7.  
    8.     private void Awake()
    9.     {
    10.         playerAnim = player.GetComponent<Animator>();
    11.     }
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         playerAnim.SetTrigger("keyPressShape");
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.         if (Input.GetButtonDown("Fire1"))
    23.         {
    24.             playerAnim.SetTrigger("keyPressShape");
    25.         }
    26.     }
     
  2. - you don't need the line 4
    - drag and drop your player in the Player Anim slot (it will hook up the Animator)
    - you don't need the line 10
    - are you sure you call the trigger "keyPressShape"? Exactly this? Can you give us a screenshot of your param tab in the animator?