Click the GUI to create the model ~! Thankyou!

alt text

Click the GUI to create the model in the scene. Creation process, the model has been attached to the mouse, how to achieve it? Thank you!

alt text

The above is what I do, I have two questions

  1. I can not follow the model created the position of the mouse
  2. If I were the terrain is level, the model can attached on the surface of the terrain

Thank you!

  1. private var moxing1 :boolean=false;

  2. private var moxing2 :boolean=false;

  3. private var moxing3 :boolean=false;

  4. private var moxing4 :boolean=false;

  5. private var moxing5 :boolean=false;

  6. var moxing1mesh : MeshFilter;

  7. var moxing2mesh : MeshFilter;

  8. var moxing3mesh : MeshFilter;

  9. var moxing4mesh : MeshFilter;

  10. var moxing5mesh : MeshFilter;

  11. var moxing1_1 :GameObject;

  12. var moxing2_1 :GameObject;

  13. var moxing3_1 :GameObject;

  14. var moxing4_1 :GameObject;

  15. var moxing5_1 :GameObject;

  16. private var windowRect1:Rect=Rect(0,0,200,200);

  17. var scrollPosition : Vector2 = Vector2.zero;

  18. var map :RenderTexture;

function Start () {

}

function OnGUI () {
windowRect1=GUI.Window(0,windowRect1,mywindow,“”);

}

function mywindow (windowID :int)
{
GUI.Box(Rect(10,20,90,90),map);

scrollPosition=GUI.BeginScrollView(Rect(110,20,80,90),scrollPosition,Rect(0,0,0,250));


moxing1=GUI.Toggle(Rect(0, 10, 100, 30), moxing1, "model1");
if(moxing1)
{
	moxing1mesh.mesh =new GameObject.Find ("moxing1mesh").GetComponent(MeshFilter).mesh;
	moxing2=false;
	moxing3=false;
	moxing4=false;
	moxing5=false;
}

moxing2=GUI.Toggle(Rect(0, 30, 100, 30), moxing2, "model2");
if(moxing2)
{
	moxing1mesh.mesh =GameObject.Find ("moxing2mesh").GetComponent(MeshFilter).mesh;
	moxing1=false;
	moxing3=false;
	moxing4=false;
	moxing5=false;
}

moxing3=GUI.Toggle(Rect(0, 50, 100, 30), moxing3, "model3");
if(moxing3)
{
	moxing1mesh.mesh =GameObject.Find ("moxing3mesh").GetComponent(MeshFilter).mesh;
	moxing1=false;
	moxing2=false;
	moxing4=false;
	moxing5=false;
}


moxing4=GUI.Toggle(Rect(0, 70, 100, 30), moxing4, "model4");
if(moxing4)
{
	moxing1mesh.mesh =GameObject.Find ("moxing4mesh").GetComponent(MeshFilter).mesh;
	moxing1=false;
	moxing2=false;
	moxing3=false;
	moxing5=false;
}

moxing5=GUI.Toggle(Rect(0, 90, 100, 30), moxing5, "model5");
if(moxing5)
{
	moxing1mesh.mesh =GameObject.Find ("moxing5mesh").GetComponent(MeshFilter).mesh;
	moxing1=false;
	moxing2=false;
	moxing3=false;
	moxing4=false;
}

GUI.EndScrollView();


if(GUI.Button(Rect(10,130,80,30),"CreatModel"))
{
	if(moxing1)
	{
		var moxing1_1_1:GameObject = Instantiate(moxing1_1,Vector3(0,10,0),Quaternion.identity);
	}
	
	if(moxing2)
	{
		
		var moxing2_1_1:GameObject = Instantiate(moxing2_1,Vector3(0,10,0), Quaternion.identity);
		
	}
	
	if(moxing3)
	{
		var moxing3_1_1:GameObject = Instantiate(moxing3_1,Vector3(0,10,0), Quaternion.identity);
	}
	
	if(moxing4)
	{
		var moxing4_1_1:GameObject = Instantiate(moxing4_1,Vector3(0,10,0), Quaternion.identity);
	}
	
	if(moxing5)
	{
		var moxing5_1_1:GameObject = Instantiate(moxing5_1,Vector3(0,10,0), Quaternion.identity);
	}
	
}



GUI.DragWindow(Rect(0,0,10000,10000));

}


The above is to create a model code. Thankyou!!

1 Answer

1

First you need to create a prefab you want the object to be created in the scene starting the GUI, after that you follow a script by loading it into the scene by the method Instatiate, and quote in the script that you want the new transform.position FORA object is equal to the mouse position on the screen, that’s just a good idea to try to implement it …

I hope I have helped

+1 Vote please