- Home /
My animation plays in scene but not in animator preview or in game.
Here is my code (Animation is on the bottom)
public class PlayerCombat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 1f;
public LayerMask enemyLayers;
void Start()
{
animator = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown("e"))
{
Attack();
}
}
void Attack()
{
Collider[] hitEnemies = Physics.OverlapSphere(attackPoint.position, attackRange, enemyLayers);
foreach (Collider enemy in hitEnemies)
{
Debug.Log("We hit " + enemy.name);
}
}
private void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
animator.SetTrigger("Attack");
}
}
unity-help.png
(256.7 kB)
Comment