Пример #1
0
        public GameObject SpawnNPC(string type)
        {
            GameObject npc = null;

            //Assign prefab to npc
            npc = npcCreator.CreateNPCPrefab(type);

            //Set the spawn position
            float   xRand    = Random.Range(-10, 10);
            float   zRand    = Random.Range(-10, 10);
            Vector3 spawnPos = playerOrCameraTransform.position +
                               playerOrCameraTransform.forward * spawnDistance +
                               new Vector3(xRand, 0, zRand);


            //If there is an NPC script on the NPC prefab, destroy it
            if (npc.GetComponent <NPC>() != null)
            {
                NPC npcScriptToRemove = npc.GetComponent <NPC>();
                DestroyImmediate(npcScriptToRemove, true);
            }

            //Add script to our npc
            npcCreator.AddNPCScript(npc, type);

            //Spawn the npc
            npc = Instantiate(npc, spawnPos, playerOrCameraTransform.rotation);

            //return the npc instance
            return(npc);
        }
Пример #2
0
        public GameObject SpawnNPC(string type)
        {
            GameObject npc = null;

            //Assign prefab to npc
            npc = npcCreator.CreateNPCPrefab(type);

            //Set the spawn position
            float   xRand    = Random.Range(-10, 10);
            float   zRand    = Random.Range(-10, 10);
            Vector3 spawnPos = playerOrCameraTransform.position +
                               playerOrCameraTransform.forward * spawnDistance +
                               new Vector3(xRand, 0, zRand);

            //Spawn the npc and assign the instance to npcInstance
            GameObject npcInstance = Instantiate(npc, spawnPos, playerOrCameraTransform.rotation);

            //Add script to our npc instance
            npcCreator.AddNPCScript(npcInstance, type);


            //return the npc instance
            return(npcInstance);
        }