Pointing Towards Prefab In C# Script

Currently whenever I want to, for example, instantiate a prefab, in my code I will put something like
public GameObject birdPrefab;
then in the inspector drag the prefab from my Assets>Prefab folder onto the variable. I was curious if there is a way to code this in my script. Something like

public GameObject birdPrefab = Assets\Prefabs\birdPrefab.prefab;

I’m sorry if this is really basic, and I’m just overlooking it, or looking in the wrong places, but I can’t find an answer.

1 Answer

1

You can put anything you want to load into a script into a folder called Resources or any subfolder of a folder called Resources:

GameObject birdPrefab = Resources.Load("Prefabs/birdPrefab");

That would load your birdPrefab from /Resources/Prefabs/birdPrefab (and Resources can be in Assets or anywhere you like).

I figured it would be something simple like that. Now I feel silly having had to ask. Haha. Thank you very much.