I need to create 2d sprite and add 2d physic rigid body to this sprite. But I need to make it in code, without unity editor. I can’t find any acrticles/tutorials for this case.
GameObject go = new GameObject("myNewSprite", typeof(SpriteRenderer), typeof(Rigidbody2D));
Or create a prefab with a sprite renderer and a rigidbody2D and do this:
public GameObject physicsSpritePrefab;
public void SomeFunction(){
GameObject go = Instantiate(physicsSpritePrefab);
}