I’m making a turret, which would shoot an object, selected randomly from an array, every couple of seconds. From several sources, and with several people’s help, I made this script:
public class shootingD : MonoBehaviour {
public Rigidbody[] projectiles = new Rigidbody[5];
public Transform MuzzlePoint;
Rigidbody MyElement;
public int magnitude;
public float shootingWait = 2.0f;
void FixedUpdate()
{
shootingWait = shootingWait+Time.deltaTime;
if (shootingWait > 2.0f)
{
shootingWait = shootingWait - 2.0f;
MyElement = projectiles [Random.Range (0, projectiles.Length)];
MyElement.gameObject.SetActive (true);
Instantiate (MyElement, MuzzlePoint.transform.position, MuzzlePoint.transform.rotation);
MyElement.useGravity = false;
MyElement.AddForce (Vector3.forward * magnitude*Time.deltaTime, ForceMode.Impulse);
}
}
}
The only problem is, that it spawns an object, which does not move. I’ve tried many alternate versions, and spent a day and a half working on this, but it still just spawns a static object.
Any help would be greatly appreciated.