Hello everyone, I am completely new to Unity and have been given a project to do for school that is very important. I need help getting some very specific coding to work so that i can move forward with the project. I need to be able to create a group of menus that allows the player to click a button and spawn a maya object in the game that they can then use to build a house. i also need to know how to write code so that the player can then move any such spawned object as if they were in the editor. after they have the house built they then need to be able to set it on fire. so can anyone help me fix the code below so that my buttons will spawn the necessary objects?
var test1:GameObject;
function OnGUI () {
// Make Flamable Materials Menu Box
GUI.Box (Rect (10,10,120,300), "Flamable Materials");
// Make the first button. If it is pressed, the Truss asset will appear on screen.
if (GUI.Button (Rect (20,40,80,20), "Truss")) {
Instantiate(test1,Vector3(0,0,0), Quaternion.identity);
}
// Make the second button. If it is pressed, a 2x4x8 Stud asset will appear on screen
if (GUI.Button (Rect (20,70,85,20), "Stud: 2x4x8")) {
print("This will spawn a 2x4x8 stud at the origin");
}
// Make the third button.If it is pressed, a 2x4x3 Stud asset will appear on screen
if (GUI.Button (Rect (20,100,85,20), "Stud: 2x4x3")) {
print("This will spawn a 2x4x3 stud at the origin");
}
// Make the fourth button.If it is pressed, a 2x4x1 Stud asset will appear on screen
if (GUI.Button (Rect (20,130,85,20), "Stud: 2x4x1")) {
print("This will spawn a 2x4x1 stud at the origin");
// Make the second button.
}
// Make the fifth button.If it is pressed, a Subfloor asset will appear on screen
if (GUI.Button (Rect (20,160,85,20), "Subfloor")) {
print("This will spawn a Subfloor pannel at the origin");
}
// Make the fifth button.If it is pressed, a Carpet asset will appear on screen
if (GUI.Button (Rect (20,190,85,20), "Carpet")) {
print("This will spawn a piece of Carpet at the origin");
}
// Make the sixth button.If it is pressed, a Drywall asset will appear on screen
if (GUI.Button (Rect (20,220,85,20), "Drywall: 4x8")) {
print("This will spawn a 4x8 Drywall pannel at the origin");
}
// Make the seventh button.If it is pressed, a Drywall asset will appear on screen
if (GUI.Button (Rect (20,250,85,20), "Drywall: 3x8")) {
print("This will spawn a 3x8 Drywall pannel at the origin");
}
// Make the eighth button.If it is pressed, a Drywall asset will appear on screen
if (GUI.Button (Rect (20,280,85,20), "Drywall: 1x1")) {
print("This will spawn a 1x1 Drywall pannel at the origin");
}
// Make Non-Flamable Materials Menu Box
GUI.Box (Rect (140,10,150,180), "Non-Flamable Materials");
// Make the First button.If it is pressed, a Door asset will appear on screen
if (GUI.Button (Rect (170,40,80,20), "Door")) {
print("This will spawn a Door at the origin");
}
// Make the second button.If it is pressed, a Sliding glass door asset will appear on screen
if (GUI.Button (Rect (160,70,120,20), "Sliding glass door")) {
print("This will spawn a Sliding Glass Door at the origin");
}
// Make the third button.If it is pressed, a Window asset will appear on screen
if (GUI.Button (Rect (170,100,85,20), "Window")) {
print("This will spawn a Window at the origin");
}
// Make the Fourth button.If it is pressed, a Foundation asset will appear on screen
if (GUI.Button (Rect (170,130,85,20), "Foundation")) {
print("This will spawn a Foundation at the origin");
}
// Make the Fourth button.If it is pressed, a Tile Floor asset will appear on screen
if (GUI.Button (Rect (170,160,85,20), "Tile Floor")) {
print("This will spawn a Tile Floor Pannel at the origin");
}
}
the code as of now is designed to only spawn a cube that im using as a test to see if the code works. every time i click the button it is assigned to i get an error message saying “UnassignedReferenceException: The variable test1 of ‘MenuButton’ has not been assigned.” however in the inspector i have it assigned to a TestCube object in my assets folder. can anyone tell me what im doing wrong or why im getting this error?