Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

How to make enemy shooting

// Some Attribute
public float fireRate = 0.5f;
private float nextFire = 0.0f;

// In Update
if(Time.time > nextFire) {
    if(!Bullet)
        return;
    nextFire = Time.time + fireRate;
    GameObject clone = Instantiate(Bullet, ShootPoint.position,ShootPoint.rotation);
    Rigidbody rb = clone.GetComponent<Rigidbody>();
    rb.AddRelativeForce(Vector3.forward * bulletSpeed, ForceMode.Impulse);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #enemy #shooting
ADD COMMENT
Topic
Name
9+4 =