An enemy in my game shoots four different projectiles with a animation trigger event calling the method. In order to keep a tidy hierarchy, I instantiante them as child objects.However, part of the animation loop involves changes in movement, and somehow every instantiated children also stops during that time. I can avoid it by not using a parent connection, but is there any other way around it?
The shooter code:
public void Shoot()
{
foreach(GameObject projectilePre in projectilePrefabs)
{
GameObject projectile = Instantiate(projectilePre, transform.position, Quaternion.identity) as GameObject;
projectile.transform.parent = transform;
}
}
And the projectile:
public class Projectile : MonoBehaviour
{
[SerializeField] float speedY = 1f, speedX = 0f;
private void Start()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(speedX, speedY);
}
private void OnTriggerEnter2D(Collider2D collision)
{
Destroy(gameObject, 0.05f);
}
}