- Home /
Trouble with instantiated GameObjects/Model in build
Hi Guys, new to Unity - trying to get my head around building and instantiating GameObjects ("Monster"s in this case) at run time.
I build the monsters first as game objects with "Monster" script attached that holds all the stats etc. Then I build a game object with the fbx model and attach to to the monster object. The issue I'm having is that everything works fine in the Game viewer in unity, but when built nothing appears on the scene.
The GameObjects on the scene at the start are:
GameMaster (which is supposed to load everything using it's Start method. BattleParams (which holds some information about what needs to be loaded) and the main camera.
The game master file looks like this:
using UnityEngine;
using System.Collections;
public class GameMaster : MonoBehaviour {
public Factory factory;
public Dice dice;
public GameObject friend, foe;
public GameObject friendModel, foeModel;
// Use this for initialization
void Start (){
dice = ScriptableObject.CreateInstance("Dice") as Dice;
// Place camera and light source
GameObject camera = GameObject.Find ("Main Camera");
camera.transform.position = new Vector3((float)-0.7, (float)0.25, (float)-0.4);
camera.transform.rotation = Quaternion.Euler(2, 70, 1);
BattleParams p = GameObject.Find ("BattleParams").GetComponent<BattleParams>(); // Holds paramaters to load with
camera.camera.fieldOfView = 30;
GameObject sun = new GameObject("Sun");
sun.AddComponent<Light>();
sun.light.color = Color.white;
sun.transform.position = new Vector3((float)3.5, 6, -3);
sun.transform.rotation = Quaternion.Euler(50, 330, -1);
sun.light.intensity = 6;
friend = GameObject.Find ("Friend");
foe = GameObject.Find ("Foe");
this.factory = (Factory)this.GetComponent("Factory");
friend = factory.buildMonster(p.friendID); // Builds monster object friend
friend.name = "Friend";
foe = factory.buildMonster(p.foeID);
foe.name = "Foe";
Monster fr = friend.GetComponent("Monster") as Monster;
Monster fo = foe.GetComponent("Monster") as Monster;
fr.foe = fo; // Reference each other
fo.foe = fr;
fo.items.Add (factory.buildItem(p.foeItemOne)); // Add items
fo.items[0].transform.parent = foe.transform;
fo.items.Add (factory.buildItem(p.foeItemTwo));
fo.items[1].transform.parent = foe.transform;
fo.items.Add (factory.buildItem(p.foeItemThree));
fo.items[2].transform.parent = foe.transform;
GameObject pre = Resources.Load("Models/Alien", typeof(GameObject)) as GameObject;
friendModel = (GameObject) Instantiate(pre, new Vector3(0, 0, 0), Quaternion.Euler((float)0, (float)92, (float)0));
fr.model = friendModel;
friendModel.transform.parent = friend.transform;
pre = Resources.Load("Models/Alien", typeof(GameObject)) as GameObject;
GameObject foeModel = (GameObject) Instantiate(pre, new Vector3(2, 0, 0), Quaternion.Euler((float)0, (float)272, (float)0));
fo.model = foeModel;
foeModel.transform.parent = foe.transform;
}
}
As mentioned, everything works fine in the Game viewer, but nothing instantiates in the build... What am I doing wrong?
Your answer
Follow this Question
Related Questions
Export objects to a .3DS file at runtime 1 Answer
Restore list elements at termination 0 Answers
Assigning sharedMaterial to object built at runtime 2 Answers
INDECIPHERABLE rendering order problem when modifying material property on Runtime 1 Answer
Am I inside a volume? (Without ray cast and default colliders?) 0 Answers