unity how to make enemy jump after you code example
Example 1: unity how to make a delay untill you can shoot again
public Transform firePoint;
public GameObject bulletPrefab;
public float bulletForce;
public float fireRate = 0.5F;
private float nextFire = 1.5F;
private void Update()
{
if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Shoot();
}
}
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody rb = bullet.GetComponent<Rigidbody>();
rb.AddForce(firePoint.forward * bulletForce, ForceMode.Impulse);
}
Example 2: how to destroy bullets when they hit a collider unity 2d
function OnCollisionEnter(){ Destroy (gameObject); }