Hello,
I'm trying to create a bear at the player's location but my code isn't working.
I tried CreatePrefab and CreateEntity but nothing work.Code:string prefab = "assets/bundled/prefabs/autospawn/animals/bear.prefab"; GameManager.server.CreatePrefab(prefab, new Vector3(), new Quaternion(), false);
I don't have any errors in the console.
Thank you in advance![]()
Solved Summon bear at player's location (C#)
Discussion in 'Rust Development' started by MrYannKee, Jan 6, 2016.
-
you have created the prefab, but not spawned it.
You have to CreateEntity first, get the BaseEntity then Spawn.
string prefab = "assets/bundled/prefabs/autospawn/animals/bear.prefab";
var createdPrefab = GameManager.server.CreateEntity(prefab, new Vector3(), new Quaternion(), false);
BaseEntity entity = createdPrefab?.GetComponent<BaseEntity>();
entity?.Spawn(true); -
Thank you
, it worked but insted of 'new Vector3()' it worked with 'player.transform.position'
-
Code:string prefab = "assets/bundled/prefabs/autospawn/animals/bear.prefab"; BaseEntity entity = GameManager.server.CreateEntity(prefab, player.transform.position, new Quaternion(), false); entity?.Spawn();
-
Oh, thank you it's easier now