using UnityEngine;
using System.Collections;
public class FiringScript : MonoBehaviour {
public GameObject Bullet;
public GameObject bulletSpawn;
private float shootTime = 0.0f;
public float shotInterval = 0.2f;
public bool inrange= false;
bool slow = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(inrange (Time.time >= shootTime) slow ==false)
{
//GameObject bullet = Instantiate(Bullet,transform.position,transform.rotation) as GameObject;
GameObject bullet = Instantiate(Bullet, bulletSpawn.transform.position,transform.rotation) as GameObject;
bullet.rigidbody.AddForce(transform.forward * 1000.0f);
shootTime = Time.time + shotInterval;
//Destroy(gameObject);
Destroy(bullet,3.0f);
}
}
void OnTriggerEnter(Collider collision)
{
if(collision.gameObject.tag == “Player”)
{
inrange = true;
}
}
void OnTriggerExit(Collider collision)
{
if(collision.gameObject.tag == “Player”)
{
inrange=false;
}
}
}