This question was
closed Mar 13, 2016 at 07:52 PM by
MrSpuriz for the following reason:
I solved it
Help with 2D Enemy Animations
So, i am making a 2D RPG game, and i have a slime with a basic chase AI, and it works fine, but i want it to have an animation, and i don't know how to set it on the enemy, i have animations in my player that are triggered by my inputs.
Here´s my AI script
using UnityEngine;
using System.Collections;
public class SlimeController : MonoBehaviour {
public Transform target;
public float speed = 2f;
public float maxDistance = 4f;
private float range;
Animator anim;
public float waitToReload;
private bool reloading;
private GameObject thePlayer;
void Start ()
{
anim = GetComponent<Animator> ();
}
void Update ()
{
range = Vector2.Distance (transform.position, target.position);
if (range < maxDistance) {
Debug.Log (range);
transform.position = Vector2.MoveTowards (transform.position, target.position, speed * Time.deltaTime);
}
if (reloading)
{
waitToReload -= Time.deltaTime;
if (waitToReload <= 0)
{
Application.LoadLevel (Application.loadedLevel);
thePlayer.SetActive (true);
}
}
}
void OnCollisionEnter2D(Collision2D other)
{
/* if(other.gameObject.name == "Player")
{
//Destroy (other.gameObject);
other.gameObject.SetActive(false);
reloading = true;
thePlayer = other.gameObject;
} */
}
}
Comment
Follow this Question
Related Questions
How to fix the rotation bug? 1 Answer
2D Spine Animation not playing 0 Answers
Import animation from Adobe Animate(JSON) 1 Answer
Should weapons be different sprites? 1 Answer