hello, so today i've been trying to make a script that basically makes the player be able to import a 3d model (only one) as a mod, but i can't seem to get the file that the player has selected, it only instantiates the object that has the script on, if you want to help me, the script is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using UnityEditor;
public class openFileSelector : MonoBehaviour
{
public GameObject LockedCube;
void Apply()
{
Object obj = Selection.activeObject as Object; //this is where i try to get the selected 3d model that the player selected.
if (obj == null)
{
EditorUtility.DisplayDialog("Select Map", "You must select an FBX first!", "OK");
return;
}
string path = EditorUtility.OpenFilePanel("Overwrite with FBX", "", "fbx");
if (path.Length != 0)
{
var fileContent = File.ReadAllBytes(path);
Instantiate(obj); //this is where i try to instantiate the selected 3d model but instead it instantiates the gameobject that the script is put on.
Destroy(LockedCube);
}
gameObject.GetComponent().enabled = false; //to prevent people from abusing the importing 3d model stuff.
}
void Start() {
Apply();
}
void Update()
{
}
}
EDIT: i think this is the right page of the forums now, tell me if it isn't.
↧