void mainObjectSetup(int pos, Vector3 point) { //retrive the prefab file.// RCFile file = Data.files[pos]; //initialize game object and add scripts to it.// GameObject gameObject = GameObject.Instantiate(file.file); Object.DontDestroyOnLoad(gameObject); gameObject.transform.position = point + new Vector3(0, 0.5f, 0); _drag = true; gameObject.AddComponent <Drag>(); MainObject obj = gameObject.AddComponent <MainObject>(); //create obj object and store. obj.position = gameObject.transform.position; obj.rotation = gameObject.transform.rotation; obj.scale = gameObject.transform.localScale; obj.nameO = file.rcname; obj.model = file.rcname; Debug.Log("file type of " + file.rcname + ":" + file.type); obj.type = file.type; obj.script = ""; obj.icode = null; obj.id = Data.objects.Count; Data.objects.Add(gameObject); }
void raycastPosition(int pos) { RCFile file = Data.files[pos]; if (file.type == ObjectType.LANDSCAPE) { placeLandscape(pos); return; } RaycastHit hit = new RaycastHit(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Debug.Log(Input.mousePosition); Ray ray2 = new Ray(Camera.main.gameObject.transform.position, Camera.main.gameObject.transform.forward); if (Physics.Raycast(ray2, out hit)) { Debug.Log("placing object:" + file.type); //objects cannot be placed without landscape.// if (file.type != ObjectType.LANDSCAPE && Data.landscape == null) { return; } placeObject(pos, hit.point, file.type); scriptSetup(Data.objects[Data.objects.Count - 1].GetComponent <MainObject>()); } }