Can't figure out resource.load

I am trying to learn how to use resource.load. I made a folder called Resources and put a prefab into said folder. Its just a sphere primitive colored red. Its called Red_Ball.

but it won’t instantiate.

here is my test code:

using UnityEngine;
using System.Collections;

public class ResourceTest : MonoBehaviour {
	
	GameObject ball ;
	
	// Use this for initialization
	void Start () {
	ball = Resources.Load("Red_Ball") as GameObject;
	GameObject go = Instantiate(ball, Vector3.up, Quaternion.identity) as GameObject;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

1 Answer

1

Lets try [Tested]:

using UnityEngine;
using System.Collections;
 
public class ResourceTest : MonoBehaviour {
      
    // Use this for initialization
    void Start () {
    GameObject go = Instantiate((GameObject)Resources.Load("Red_Ball"), Vector3.up, Quaternion.identity) as GameObject;
}
 
    // Update is called once per frame
    void Update () {
 
    }
}