
アニメーターコントローラーで次のステートに遷移するときに、「または」を使った条件を設定します。
まず2つのトリガーパラメーターと、2つのステートを行き来する遷移を作ります。

右側の矢印をクリックしてインスペクタのConditionsに、2つのトリガーパラメーターの条件を追加してみます。Has Exit Timeは外します。

これだと、Conditionsに設定した条件が全て満たされないと遷移しないので、両方のトリガーがセットされないといけません。
using UnityEngine;
public class TestScript : MonoBehaviour
{
Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent();
}
// Update is called once per frame
void Update()
{
// 左クリック
if (Input.GetMouseButtonDown(0)) animator.SetTrigger("Trigger1");
// 右クリック
if (Input.GetMouseButtonDown(1)) animator.SetTrigger("Trigger2");
}
}

片方のクリックでは遷移せず、もう片方もクリックされないと遷移しないのがわかります。
Trigger1とTrigger2のどちらかがセットされると遷移するようにするには、遷移の矢印をもう一本付けます。遷移を作るには、ステートを右クリックしてMake Transitionを選択し、遷移先のステートをクリックします。


三角形が3つ並んだ方の矢印を選択してインスペクタを見ると、Transitionsに遷移がもう一つ追加されています。
片方の遷移を選択し、Trigger2の条件だけを設定します。

もう片方はTrigger1だけにします。

これで2つの条件のどちらかが満たされたときに遷移するようになります。

2つの遷移の名前が同じでわかりにくいですが、遷移には自由に名前をつけることができます。また、マイナスボタンで選択中の遷移を削除できます。


この名前はAnimator.GetAnimatorTransitionInfoを使って遷移中か調べるときに使えます。
Animator animator;
animator = GetComponent();
// Trigger1を通って遷移している時
if(animator.GetAnimatorTransitionInfo(0).IsUserName("Trigger1"))
{
Debug.Log("Trigger1");
}
こうすると、同じ矢印を通っても、右クリックのときはメッセージが表示されません。
