- Home /
How do I play legacy animations properly in Unity C#
I am have a problem playing the enemy animations . I have all of my animation set on loop . I can't use animation controller because the animation has to be set on legacy . The problem I am having is when I click on play all three of my animations wont work . I need Idle , move , attack, animation all working together . I only gotten the move , and attack animation to work . Another problem occur the enemy floats in mid air . When I try to put the all three animations together get errors . I just need the enemy attack when the player is near and chase when the player is far away and idle when the player is dead and idle when the player is far far away like on the other side of the level . Here is my script :
using UnityEngine; using System.Collections;
public class attack01 : MonoBehaviour { private health2016 health2016Script; public GameObject player; public bool playerInRange; public int attackDamage = 25; public bool damage; public Transform enemy; public float playerDistance; public float rotationDamping; public float chaseRange; public NavMeshAgent nav;
void Awake () { GameObject Player = GameObject.FindWithTag("Player"); health2016Script = Player.GetComponent();
}
void Update
{ playerDistance = Vector3.Distance (player.position, transform.position);
if (playerDistance < 15f) { lookAtPlayer();
}
if (playerDistance < 40f)
{
nav = GetComponent <NavMeshAgent> ();
nav.SetDestination (player.position);
}
if(playerDistance > 2f)
{
chase();
}
else if (playerDistance < 7f)
{
attack();
}
}
void lookAtPlayer()
{
Quaternion rotation = Quaternion.LookRotation (player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping);
Animation.Play("idle");
}
void chase()
{
GetComponent<Animation>().Play("move");
}
void attack() {
void OnTriggerEnter ( Collider other ) { if(other.gameObject == player) { playerInRange = true;
health2016Script.TakeDamage (attackDamage);
Animation.Play("attack");
}
}
health2016Script.TakeDamage (attackDamage);
GetComponent<Animation>().Play("attack");
}
}
}
}
}
Answer by JacksonPeeven · Jun 05, 2016 at 03:52 PM
Hello, @importguru88! What are the errors you are receiving?
Your answer
Follow this Question
Related Questions
How to play animation (C#) 3 Answers
Legacy animation not playing - no errors? 1 Answer
Animator not showing animation 1 Answer
help me please dont understand problem with animation 0 Answers