Hi, I’m new to Unity. All I want to do is write a script that takes a Prefab from the Resources folder, and puts it in the scene (as opposed to me dragging and dropping it). My prefab (called “Dummy”) is in a folder called “Resources” within Assets, and I’m trying to load it into a GameObject called guy. However, with my code, I always end up with a null GameObject. What have I done wrong?
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public GameObject guy = Resources.Load("Dummy") as GameObject;
void Start () {
if (guy == null) {
Debug.Log ("IT'S NULL!!!");
}
Instantiate (guy, new Vector3(400, -2, 115), Quaternion.identity);
}
void Update () {
}
}