I want to spawn some rigidbodies and apply some initial force to them on spawning.But i want the rigidbodies to spawn in FixedUpdate and add force to them there.However I spawn them on user input and the input is taken in Update for avoiding misses as compared to FixedUpdate .So i tried and wrote the following code in C#
void FixedUpdate()
{
while(InputCount!=0)
{
temp = Instantiate(bomb,childTransform.position,Quaternion.identity)as GameObject;
temp.rigidbody.AddForce(this.transform.right*(-1)*forceAmount);
InputCount--;
}
}
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
InputCount++;
}
}
Here I had Single input so I just incremented its count,But in general case I intend to keep a hash map with keys with their count and supply it to FixedUpdate from Update as in above code.Is there any standard practice for doing this or I am doing it right?