I'm working on a game with a friend and I'm having trouble making the Ai shoot every 3 seconds. The code now makes the AI shoot when the Player's Ships are in range.
using UnityEngine;
using System.Collections;
public class Enemy1_Shoot : MonoBehaviour {
public Rigidbody bullet;
public float speed = 10f;
void OnTriggerStay(Collider other)
{
if(other.gameObject.tag == "noobShip")
{
FireBullet();
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void FireBullet()
{
Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
bulletClone.velocity = transform.forward * speed;
}
}
↧