Hi, I am working on an editor menu item that simplifies my object placement. (I repeatedly
place the same prefab in the scene en this script makes it easier).
But I keep getting a null return in my Debug.Log and the prefab does not get instantiated in the editor.
I checked if the file existed, it did, I checked if the path was correct, it was correct. All other applications directly find the file except for this editor function.
Any help would be great.
#pragma strict
@MenuItem ("GameObject/Create Other/Spawn",false,-16)
static function SpawnGenerator () {
var path:String= Application.dataPath+"MyAssets/Scripts/FX/Source/Place.prefab";
var prefab: GameObject= AssetDatabase.LoadAssetAtPath(path, typeof (GameObject)) as GameObject;
var ray : Ray= Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, 1000)){
Debug.Log(hit.point);
}
if(prefab){
var Place:GameObject = GameObject.Instantiate (prefab, hit.point , Quaternion.identity);
}
Debug.Log(prefab);
Debug.Log(Place);
}