I’m using the code from Unity’s Instantiate tutorial (very slightly modified) to create projectiles in my project. However, I’m noticing that it works inconsistently. Most of the time when I click “Fire1” it creates one projectile properly. But other times it will either not create any projectile or create two of them that will launch at once. Here’s my code:
using UnityEngine;
using System.Collections;
public class UsingInstantiate : MonoBehaviour
{
public Rigidbody rocketPrefab;
public Transform barrelEnd;
public int shotSpeed;
void FixedUpdate()
{
if(Input.GetButtonDown("Fire1"))
{
Rigidbody rocketInstance;
rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
rocketInstance.AddForce(barrelEnd.forward * shotSpeed);
}
}
}
Here’s the original tutorial for reference:
http://unity3d.com/learn/tutorials/modules/beginner/scripting/instantiate?playlist=17117
Any ideas what the problem is in my version, or if something else might be the cause?