Hi.I made An animation for my gun called “shootwithm9”
i have a bullet called “Bullet”
and i wrote a script for shooting
and im getting errors
this is my script:
using UnityEngine;
using System.Collections;
public class M9 : MonoBehaviour {
public Transform M9bullet;
public Transform BulletSpawn;
public int OurAmmo = 100;
private RaycastHit hit;
private Vector3 dir;
private Quaternion rot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (animation.isplaying("shootwithm9") == false) {
if (Input.GetButtonDown ("Fire1")) {
if (OurAmmo > 0) {
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0));
if (Physics.Raycast(Ray, out hit)) {
dir = (hit.point - BulletSpawn.position).normalized;
}
else {
dir = ray.direction;
}
rot = Quaternion.FromToRotation (-M9bullet.transform.forward, dir);
Instantiate(M9bullet, BulletSpawn.position, rot);
Animation.Play ("shootwithm9");
audio.Play();
OurAmmo -= 1;
}
}
}
//CheckAmmo
}
}
Check The Script.
Thank you
and sorry for bad english