I have an Enemy with Animator Animations that are working. I’m using RAIN AI for the AI and need to use my own script for this part because I am not familiar with doing this with RAIN. Basicaly what I need to do, is when my enemy gets to the “idle_aiming” animation, I need it to start shooting at me. I have this script that is a tweaked version of the player shooting script for my player to shoot the enemy. Well, everything works but I thought I could put this on my bullet spawn on the gun for the enemy but it doesn’t work because the animator controller is the enemy. And when i put this on the enemy, some very strange things happen because the bullet spawn is coming from??? Not sure where. Please help.
Here is the script
using UnityEngine;
using System.Collections;
public class EnemyShootPlayer : MonoBehaviour
{
public Animator anim;
public float bulletSpeed = 10;
public Rigidbody bullet;
void Start ()
{
anim = GetComponent<Animator>();
}
void ShootPlayer()
{
Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
bulletClone.velocity = transform.forward * bulletSpeed;
}
void FixedUpdate ()
{
if (anim.GetCurrentAnimatorStateInfo(0).IsName("idle_aiming"))
ShootPlayer();
}
}