• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Mar 13, 2016 at 07:52 PM by MrSpuriz for the following reason:

I solved it

avatar image
0
Question by MrSpuriz · Mar 04, 2016 at 01:40 AM · animation2dairpg

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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zoogyburger · Mar 13, 2016 at 07:33 PM 0
Share

I'm having trouble on this too.

0 Replies

  • Sort: 

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix the rotation bug? 1 Answer

Trying to impliment a 2D sidescroller enemeny follow player AI. Getting UnassignedReferenceException. Now idea how to fix, been lurking for days 2 Answers

Vector 2 only using x (Enemy AI) 1 Answer

Enemy is not taking damage! 0 Answers

My animation will stop shortly then start again, causing it to look bad 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges