im currently working on a script that creates an object and fires it. i have it set to transform.forward so i know that is should be firing in the right direction. the problem is that even with the rb.addforce (yes ive checked if its finding the rigidbody, it is) its not moving no matter how high i put the speed variable, can anyone help?
public GameObject firePrefab;
public Transform firepoint;//Predetermined spawnpoint
public Animator anim;
public Rigidbody rb;
public float speed;
public GameObject childfire;
public GameObject Player;
private void Start()
{
childfire = gameObject.transform.Find("fire").gameObject;
firePrefab = Resources.Load("fire") as GameObject;
firepoint = gameObject.transform;
anim = gameObject.GetComponent<Animator>();
rb = firePrefab.GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
Debug.Log("m1");
StartCoroutine(firetime());
}
else
{
anim.SetBool("Fire",false);
}
}
IEnumerator firetime()
{
anim.SetBool("Fire", true);
childfire.SetActive(false);
yield return new WaitForSeconds(0.4f);
CastFire(firePrefab, firepoint.transform.position, firepoint.transform.rotation);
rb.AddForce(transform.forward * speed * Time.deltaTime);
yield return new WaitForSeconds(0.4f);
childfire.SetActive(true);
}
//"fire"' method
void CastFire(GameObject prefab, Vector3 position, Quaternion rotation)
{
GameObject fireObject = Instantiate(firePrefab, firepoint.position, Quaternion.identity);
}