I made a script for someone in that past, that incorporated animations and projectiles!! here it is!!
var fireSound : AudioClip;
var clipSize = 10;
var compTime = 1;
private var bullets : int;
var clips = 10;
var barrel : Transform;
var projectile : Rigidbody;
var speed = 30.0;
var reload : boolean = false;
function Awake () {
animation["fire"].speed = 2;
animation["idle"].wrapMode = WrapMode.Loop;
animation["fire"].wrapMode = WrapMode.Clamp;
animation["reload"].wrapMode = WrapMode.Clamp;
animation.Play("idle", PlayMode.StopAll);
bullets = clipSize;
}
function Update () {
if (clips >= 0) {
if (Input.GetKey("e") bullets >= 1 animation.IsPlaying("idle")) {
SendMessage("Fire");
}
else if (bullets <= 0 !reload) {
reload = true;
SendMessage("Reload");
SendMessage("InvokeReload");
}
else if (!animation.isPlaying) {
SendMessage("Idle");
}
}
if (bullets > clipSize) {
bullets = clipSize;
}
if (clips <= 0) {
SendMessage("Idle");
}
}
function Fire () {
animation.Play("fire");
bullets -= 1;
var Projectile : Rigidbody = Instantiate(projectile, barrel.position, barrel.rotation);
Projectile.velocity = transform.TransformDirection(Vector3 (speed, 0, 0));
if (fireSound)
AudioSource.PlayClipAtPoint(fireSound, transform.position);
}
function Reload () {
animation.Play("reload", PlayMode.StopAll);
yield WaitForSeconds(animation["reload"].length);
bullets = clipSize;
reload = false;
}
function Idle () {
animation.Play("idle");
}
function InvokeReload () {
clips -= 1;
}
function OnGUI () {
GUI.Box( Rect(Screen.width - 110,Screen.height - 30, 100, 25), "Clips left " + (clips));
GUI.Box( Rect(Screen.width - 110,Screen.height - 70, 100, 25), "Bullets left " + (bullets));
}
hope some people can use it!! I don’t care if you use it in your game, and if you want, you can put my company name in the credits. NOTE: this script requires a reload animation, fire animation, and idle animation.