(Huuuuge C# newbie, here)
When my character is close enough to an object (dice) and then clicks the object, an animation plays of the character grabbing the object.
The animation plays, but it loops and never ends. I just want it to play once and then stop.
This is the code I’ve added to the object that gets picked up:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiceScript : MonoBehaviour {
public bool GrabBool;
public Animator PlayerAnimator;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetKey(KeyCode.Mouse0))
{
Collider[] hits = Physics.OverlapSphere (transform.position, 1);
foreach (Collider hit in hits)
{
if (hit.tag == "Player") {
Destroy (gameObject);
PlayerAnimator.SetBool ("GrabBool", true);
}
}
}
}
}

Everything works, except for the animation problem.
I’m going bonkers over here.
Thanks.