admin管理员组文章数量:1221252
Using this code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
public class PlayerCombat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public int attackDamage = 40;
// Update is called once per frame
void Update()
{
Attack();
}
void Attack()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
animator.SetTrigger("Attack");
Collider[] hitEnemies = Physics.OverlapSphere(attackPoint.position, attackRange, enemyLayers);
foreach (Collider enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
animator.SetBool("Block", true);
}
else if (Input.GetKeyUp(KeyCode.Mouse1))
{
animator.SetBool("Block", false);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
I'm trying to trigger animations. Ignore the Gizmos and the enemy parts just the animator stuff. In unity using this:
AnimationWindow
When I make transitions from "Any State" these two some thing breaks and I can only do the attack animation while holding down block. I want to know how to fix this.
Using this code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
public class PlayerCombat : MonoBehaviour
{
public Animator animator;
public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public int attackDamage = 40;
// Update is called once per frame
void Update()
{
Attack();
}
void Attack()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
animator.SetTrigger("Attack");
Collider[] hitEnemies = Physics.OverlapSphere(attackPoint.position, attackRange, enemyLayers);
foreach (Collider enemy in hitEnemies)
{
enemy.GetComponent<Enemy>().TakeDamage(attackDamage);
}
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
animator.SetBool("Block", true);
}
else if (Input.GetKeyUp(KeyCode.Mouse1))
{
animator.SetBool("Block", false);
}
}
void OnDrawGizmosSelected()
{
if (attackPoint == null)
return;
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}
}
I'm trying to trigger animations. Ignore the Gizmos and the enemy parts just the animator stuff. In unity using this:
AnimationWindow
When I make transitions from "Any State" these two some thing breaks and I can only do the attack animation while holding down block. I want to know how to fix this.
Share Improve this question edited Feb 6 at 21:01 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 6 at 20:44 Justus TateJustus Tate 32 bronze badges 3- whats the conditions on those transitions – BugFinder Commented Feb 6 at 20:50
- the default ones, but only exit time between swing and idle – Justus Tate Commented Feb 6 at 20:53
- well there are no default conditions, so, thats confusing in its own right. – BugFinder Commented Feb 6 at 22:40
1 Answer
Reset to default -1From the code perspective, this looks correct. From understanding your code behaviour, you are update the state of the animation's "Block" value when the user is holding the mouse down or not.
The problem appears to be in your Animator's controller; without further context on what your animation tree looks like, and any parameters you have setup, it will be difficult to answer this question correctly.
My advice would be to check whether there's a condition assigned to your animation clip tree.
本文标签: My animations are breaking in Unity using CStack Overflow
版权声明:本文标题:My animations are breaking in Unity using C# - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739360774a2159805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论