Assign a prefab using C# script

Ok, so I am trying to assign a prefab using c# script, I dont want to use the editor drag and drop because this script is only applied when the “B” button is pressed, I need the prefab to be assigned when the script enables. I have searched the forums and cannot find a solution.

public class Bow : MonoBehaviour
{
    public Rigidbody ArrowPrefab;  
    public float ArrowSpeed = 50.6f;
    public float fireRate = 1.5f;
    public float nextFire = 0.0f;
    public float pullStartTime = 0.0f;
    public float pullTime = 0.5f;
    public float maxStrengthPullTime = 3.0f; // how long to hold button until max strength reached	
    public int Arrow = 1;
    public int maxArrowCount = 10;
    public List arrowList;
    bool falsePull;
    
    void  Start ()
    {
        falsePull = false;
        ArrowPrefab = Resources.Load("ArrowPrefab", Rigidbody);
        arrowList = new List();
    }
    
    void  Update ()
    { 
    	// pull back string 
    	if(Input.GetMouseButtonDown(0))
    	{
    		if(Time.time > nextFire)
    		{			
    			pullStartTime = Time.time; //store the start time
    		}
    		else
    			falsePull = true; 
    		}
     
    		// fire arrow 
    		if(Input.GetMouseButtonUp(0))
    		{
    			if(!falsePull)
    			{
    				nextFire = Time.time + pullTime; // actual fire rate 
    				//animation.Play("FIRE");
    				float timePulledBack= Time.time - pullStartTime; // this is how long the button was held
    				if(timePulledBack > maxStrengthPullTime) // this says max strength is reached 
    				timePulledBack = maxStrengthPullTime; // max strength is ArrowSpeed * maxStrengthPullTime
    				float arrowSpeed= ArrowSpeed * timePulledBack; // adjust speed directly using pullback time
    				
    				//count and fire arrows			
    			    for(int i = 0; i < Arrow; i++)
    			    {
    			        Rigidbody item = Instantiate(ArrowPrefab, GameObject.Find("FIREPOINT").transform.position, transform.rotation) as Rigidbody;
    					Physics.IgnoreCollision(ArrowPrefab.collider, transform.root.collider); 
    					item.rigidbody.AddForce(transform.forward * arrowSpeed); 
    					arrowList.Add(item.transform);
    						if(Arrow <= maxArrowCount)
    						{
    							arrowList.RemoveAt(10);
    							Destroy(GameObject.FindGameObjectWithTag("Arrow"));
    						}
    			    }
    			    Transform[] transform_list = arrowList.ToArray();			
    			}
    		else
    		falsePull = false;		
    		}		
    	}
    }

You really should work more with prefabs.

Just create an empty Gameobject, attach your Bow script and make a Bow prefab of this object. Now you can assign your arrow prefab to the “ArrowPrefab” variable of your bow prefab. If you need a bow, just instantiate it from your player script or whereever you handle your “B” key.

Another way is to simple disable the bow script from the begining and enable it when you need it. That way the Bow script is always there.