Problem is not reproducible or outdated
How to instantiate Object to specific location?
I have this code:
private void PopulateServerEntities()
{
var globals = FindObjectOfType<GlobalAssets>();
var npc = Instantiate<GameObject>(globals.NetworkEntityStatePrototype);
var chest = Instantiate<GameObject>(globals.NetworkEntityStatePrototype);
npc.GetComponent<NetworkEntityState>().PrefabType = PrefabType.Npc;
chest.GetComponent<NetworkEntityState>().PrefabType = PrefabType.Chest;
NetworkServer.Spawn(npc);
NetworkServer.Spawn(chest);
}
And would like to spawn the chest object at 10, 10, 10 so I used
var chest = Instantiate<GameObject>(globals.NetworkEntityStatePrototype, new Vector3(10, 10, 10), Quaternion.identity);
But it just doesn't work, the object is still at 0, 0, 0
Is there anything wrong with this approach?
Answer by hdtnl · Jan 03, 2017 at 05:50 PM
I think you should do that:
var chest = Instantiate(globals.NetworkEntityStatePrototype, new Vector3(10, 10, 10), Quaternion.identity) as GameObject;
or this:
var chest = Instantiate<GameObject>(globals.NetworkEntityStatePrototype);
chest.transform.position = location;
i tried like this: var chest = Instantiate(globals.NetworkEntityStatePrototype); chest.transform.position = new Vector3(120, 120, 120);
it just spawned at 0,0,0
Follow this Question
Related Questions
How to make another ground spawn beneath itself 1 Answer
I got Some Error about how to Transform Postiton Enemy where one point can spawn 2 enemies. 1 Answer
How to get the position of a new Instantiated prefab 0 Answers
Problem with aiming Script(Only Some Code Works) 0 Answers
Argument `#1' cannot convert `float' expression to type `UnityEngine.Vector3 ? 1 Answer