public void SpawnRock() { var rock = instantiator.InstantiatePrefab(rockPrefab); rock.transform.position = rockSpawnPoint.position; rock.GetComponent <Rigidbody>().AddForce(rockDirection * rockForce, ForceMode.Impulse); }
private GameObject InstantiateScreen() { if (m_PrefabLoadingStrategy == PrefabLoadingStrategy.FromResource) { m_Prefab = Resources.Load <GameObject>(m_PrefabPath); } return(m_Instantiator.InstantiatePrefab(m_Prefab)); }
public void PreAllocate(int allocationCount) { for (var i = 0; i < allocationCount; i++) { var newInstance = _instantiator.InstantiatePrefab(Prefab); newInstance.SetActive(false); _pooledObjects.Push(newInstance); } }
private void Execute() { GameObject go = m_Instantiator.InstantiatePrefab(m_Prefab); if (m_Parent != null) { go.transform.SetParent(m_Parent, false); } }
public void SpawnExplosionAt(Vector3 position, float power) { var delta = _settings.ExplosionDelayMax - _settings.ExplosionDelayMin; var delay = delta * power; Observable.Timer(TimeSpan.FromSeconds(_settings.ExplosionDelayMin + delay)).Subscribe((l) => { var explosionObject = _instantiator.InstantiatePrefab(_prefab, position, Quaternion.identity, null); }); }
public void PreAllocate(int allocationCount) { for (var i = 0; i < allocationCount; i++) { var newInstance = _instantiator.InstantiatePrefab(Prefab); newInstance.SetActive(false); var objectContainer = new ViewObjectContainer(newInstance); _pooledObjects.Add(objectContainer); } }
private GameObject CreatePlayer(string id, Vector3 position, Quaternion rotation, bool isRemote = true) { var gobj = container.InstantiatePrefab(playerPrefab, position, rotation, null); gobj.name = $"Player:{id}"; // TODO: improve if (!isRemote) { container.InstantiateComponent <LocalMovement>(gobj); } return(gobj); }
public IEnumerable <GameObject> Create(MapObjectKind kind, Vector2 position) { var infos = _prototypes[kind]; foreach (var info in infos) { var go = _instantiator.InstantiatePrefab(info.Prefab); go.transform.position = position + info.Offset; yield return(go); } }
public ISceneItem Create(SceneItemData param) { GameObject prefab = m_TemplateStorage.GetDataForType(param.payloadType, param.payload)?.sceneItemPrefab; ISceneItem item = m_Instantiator.InstantiatePrefab(prefab).GetComponent <ISceneItem>(); item.identifiable.identifier = param.id; item.itemTransform.localPosition = param.position; item.itemTransform.localRotation = Quaternion.Euler(param.rotation); item.scalable.size = param.size; item.levelable.level = param.levels; item.payloadViewController.SetPayload(param.payloadType, param.payload, param.delay); item.colorable.color = param.color; m_SceneItemRegistry.RegisterItem(item); return(item); }
public IStepItem Create(WorkflowStepData param, UnityEngine.Object prefab) { IStepItem item = m_Instantiator.InstantiatePrefab(prefab).GetComponent <IStepItem>(); item.identifiable.identifier = Guid.ParseExact(param.id, "N"); item.duration = param.durations[0]; item.repetitions = param.repetitions; item.automatic = param.automatic; item.triggerId = param.triggerId; item.name = param.name; byte levels = 0; foreach (SceneItemData itemData in param.items) { ISceneItem sceneItem = m_ItemFactory.Create(itemData); item.Add(sceneItem); levels |= sceneItem.levelable.level; } return(item); }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { //When any data is received it will be passed here, //we then need to process it if it's got a tag of 0 and, if //so, create an object. This is where you'd handle most admin //stuff like that. //Ok, if data has a Controller tag then it's for us if (tag == TagIndex.Controller) { //If a player has joined tell them to give us a player if (subject == TagIndex.ControllerSubjects.JoinMessage) { //Basically reply to them. DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position); } //Then if it has a spawn subject we need to spawn a player if (subject == TagIndex.ControllerSubjects.SpawnPlayer) { //Instantiate the player // GameObject clone = (GameObject)Instantiate (playerObject, (Vector3)data, Quaternion.identity); GameObject clone = instantiator.InstantiatePrefab(playerObject); clone.transform.position = (Vector3)data; clone.transform.rotation = Quaternion.identity; //Tell the network player who owns it so it tunes into the right updates. clone.GetComponent <NetworkPlayer>().networkID = senderID; //If it's our player being created allow control and set the reference if (senderID == DarkRiftAPI.id) { clone.GetComponent <CharacterUserControl>().IsControllable = true; player = clone.transform; } } } }
private void SpawnEnemy(EnemyData enemy, int count) { var spawnRenderer = _spawnzone.GetComponent <Renderer>(); var bounds = spawnRenderer.bounds; var randomPoint = bounds.center + new Vector3( (Random.value - 0.5f) * bounds.size.x, (Random.value - 0.5f) * bounds.size.y, (Random.value - 0.5f) * bounds.size.z ); for (int i = 0; i < count; i++) { NavMeshHit hit; if (!NavMesh.SamplePosition(randomPoint, out hit, 3f, NavMesh.GetAreaFromName(SPAWN_NAV_MESH_LAYER))) { Debug.LogError("Failed to get random position on spawn nav mesh layer"); return; } var prefab = enemy.Prefab; _instantiator.InstantiatePrefab(prefab, hit.position, Quaternion.identity, null); } }
public void Tick() { if (_stopUpdating) { return; } if (_agent.hasPath && (_winLoseController.GameLost || _winLoseController.GameWon)) { _agent.isStopped = true; _agent.ResetPath(); _stopUpdating = true; } if (_agent.hasPath && (_mainTransform.position - _destination.transform.position).magnitude <= 0.4f) { if (_hitEffect != null) { _instantiator.InstantiatePrefab(_hitEffect, _mainTransform.position, _mainTransform.rotation, null); } _healthController.DecrementHealth(); UnityEngine.Object.Destroy(_mainTransform.gameObject); } }