Instantiate() public static method

Instantiate a prefab over the network. This prefab needs to be located in the root of a "Resources" folder.
Instead of using prefabs in the Resources folder, you can manually Instantiate and assign PhotonViews. See doc.
public static Instantiate ( string prefabName, Vector3 position, Quaternion rotation, int group ) : GameObject
prefabName string Name of the prefab to instantiate.
position Vector3 Position Vector3 to apply on instantiation.
rotation Quaternion Rotation Quaternion to apply on instantiation.
group int The group for this PhotonView.
return GameObject
Esempio n. 1
0
    private void RPC_CreatePlayer()
    {
        GameObject obj = PhotonNetwork.Instantiate(Path.Combine("Prefabs", "PlayerSoul"), CanvasGameButton.Instance.spawner1[joinRoomNum - 1].transform.position, Quaternion.identity, 0);

        CurrentPlayer = obj.GetComponent <PlayerMovement> ();
    }
Esempio n. 2
0
 public override void OnJoinedRoom()
 {
     base.OnJoinedRoom();
     spawnedPlayerPrefab = PhotonNetwork.Instantiate("Prefabs/PlayerPrefab", transform.position, Quaternion.identity);
 }
Esempio n. 3
0
 public void Spawn(string name)//버튼에 할당한 name으로 prefab인스턴스 생성
 {
     PhotonNetwork.Instantiate(name, Vector3.zero, Quaternion.identity);
 }
Esempio n. 4
0
    void OnGUI()
    {
        GUILayout.Space(0);
        GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());

        if (PhotonNetwork.connectionState == ConnectionState.Disconnected)
        {
            if (GUILayout.Button("Connect"))
            {
                PhotonNetwork.ConnectUsingSettings("1.0");
                Debug.Log("Server Connect");
            }
        }
        else if (PhotonNetwork.connectionStateDetailed.ToString() == "JoinedLobby")
        {
            startcheck  = false;
            cam.enabled = true;
            if (GUILayout.Button("Disconnect"))
            {
                PhotonNetwork.Disconnect();
                Debug.Log("Server Disconnect");
            }

            GUILayout.Label("Enter Room Name :");
            roomName = GUILayout.TextField(roomName);
            GUILayout.Label("Set Player Name :");
            playerName = GUILayout.TextField(playerName);
            PhotonNetwork.player.name = playerName;
            if (GUILayout.Button("Create Room"))
            {
                PhotonNetwork.CreateRoom(roomName, true, true, 2);
                Debug.Log("Create Room");
            }
            if (GUILayout.Button("Join Room"))
            {
                PhotonNetwork.JoinRoom(roomName);
                Debug.Log("Join Room");
            }
            if (GUILayout.Button("Join Random Room"))
            {
                PhotonNetwork.JoinRandomRoom();
                Debug.Log("Join Random Room");
            }
            GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");

            if (PhotonNetwork.GetRoomList().Length == 0)
            {
                GUILayout.Label("Currently no games are available.");
            }
            else
            {
                GUILayout.Label(PhotonNetwork.GetRoomList() + " currntly available. Join either:");

                this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
                foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
                {
                    if (roomInfo.playerCount != roomInfo.maxPlayers)
                    {
                        GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
                        if (GUILayout.Button("Join"))
                        {
                            PhotonNetwork.JoinRoom(roomInfo.name);
                        }
                    }
                }
                GUILayout.EndScrollView();
            }
        }
        else if (PhotonNetwork.connectionStateDetailed.ToString() == "Joined")
        {
            if (GUILayout.Button("Left Room"))
            {
                cam.enabled = true;
                PhotonNetwork.LeaveRoom();
                Debug.Log("Leave Room");
            }
            int i = 0;
            foreach (PhotonPlayer p in PhotonNetwork.playerList)
            {
                i++;
            }
            GUILayout.Label("Room Name : " + roomName);
            GUILayout.Label("Player Count : " + i);
            GUILayout.Label("Current Join Player");
            i = 0;
            foreach (PhotonPlayer p in PhotonNetwork.playerList)
            {
                i++;
                GUILayout.Label(i + " user : "******"Start"))
                        {
                            startcheck  = true;
                            cam.enabled = false;
                            string name = (PhotonNetwork.isMasterClient == true) ? "Player_1" : "Player_2";
                            //Scene Object
                            player = PhotonNetwork.Instantiate(name, new Vector3(31f, 7f, 62f), Quaternion.identity, 0, null);
                        }
                    }
                    else if (GUILayout.Button("Ready"))
                    {
                        if (PhotonNetwork.isMasterClient == true)
                        {
                            if (GetComponent <Room_server>().Rready == false)
                            {
                                GetComponent <Room_server>().Rready = true;
                            }
                            else
                            {
                                GetComponent <Room_server>().Rready = false;
                            }
                        }
                        else
                        {
                            if (GetComponent <Room_server>().ready == false)
                            {
                                GetComponent <Room_server>().ready = true;
                            }
                            else
                            {
                                GetComponent <Room_server>().ready = false;
                            }
                        }

                        Debug.Log("ready : " + GetComponent <Room_server>().ready);
                        Debug.Log("Rready : " + GetComponent <Room_server>().Rready);
                    }
                }
                else
                {
                    cam.enabled = false;
                }
            }
        }
    }
 private void OnEnable()
 {
     fogParticle = PhotonNetwork.Instantiate("Fog", fogSpawnPos.transform.position, fogSpawnPos.transform.rotation, 0);
 }
Esempio n. 6
0
 public void SpawnPlayer()
 {
     PhotonNetwork.Instantiate("Player", this.transform.position, this.transform.rotation);
     available = false;
     Debug.Log("Player " + PhotonNetwork.LocalPlayer.ActorNumber + " spawned");
 }
Esempio n. 7
0
 private void RPC_CreatePlayer()
 {
     //creates player network controller but not player character
     PhotonNetwork.Instantiate(Path.Combine("PhotonPrefab", "PhotonNetworkPlayer"), transform.position, Quaternion.identity, 0);
 }
Esempio n. 8
0
    /// <summary>
    /// 获取新武器
    /// </summary>
    /// <param name="weaponName"></param>
    public void GetNewWeapon(string weaponName)
    {
        //GameObject gobj = ObjectPool.Instance.GetObj(weaponName);
        //网络实例化
        if (!phv.IsMine)
        {
            return;
        }
        gobj = PhotonNetwork.Instantiate(weaponName, transform.position, Quaternion.identity);

        gobj.GetComponent <WeaponAtrribute>().SetFather(GetComponent <PhotonView>().ViewID);
        //去掉克隆
        gobj.name = gobj.name.Replace("(Clone)", "");
        //获取子弹脚本
        BulletCSharp bulletCSharp = gobj.GetComponent <BulletCSharp>();

        //如果有子弹脚本,代表这是武器
        if (bulletCSharp != null)
        {
            //防止脱手
            gobj.GetComponent <Rigidbody>().isKinematic = true;
            //位置归零
            Destroy(bulletCSharp);
            //子弹初始化
            BulletInit(gobj, gameObject.transform);
        }
        //攻击等于数据库查找到的类型
        int attackType = DBA.Instance.GetWeaponTypeByName(weaponName);

        //武器类型等于查找到的攻击类型
        WeaponType = attackType;
        //当前武器等于生成的武器名字
        currentWeaponName = gobj.name;
        //如果没找到手就在找一遍
        if (handOfPlayers == null)
        {
            handOfPlayers = transform.GetComponentsInChildren <HandOfPlayer>();
        }

        for (int i = 0; i < handOfPlayers.Length; i++)
        {
            //有手就清除武器;
            handOfPlayers[i].ClearCurrentWeapon();
        }
        //如果类型1、2
        if (attackType == 1 || attackType == 2)
        {
            for (int i = 0; i < handOfPlayers.Length; i++)
            {
                if (handOfPlayers[i].handType == HandType.Right)
                {
                    handOfPlayers[i].ChangeCurrentWeapon(gobj);
                }
            }
        }
        //类型3、4
        if (attackType == 3 || attackType == 4)
        {
            for (int i = 0; i < handOfPlayers.Length; i++)
            {
                if (handOfPlayers[i].handType == HandType.Left)
                {
                    handOfPlayers[i].ChangeCurrentWeapon(gobj);
                }
            }
        }
        //武器动画
        ChangeAttackAnimator(currentWeaponName);
    }
Esempio n. 9
0
 GameObject IUtilityCore.initPlayer(GameObject prefab)
 {
     return(PhotonNetwork.Instantiate(prefab.name, Vector3.up * 10, Quaternion.identity, 0));
 }
Esempio n. 10
0
 void SpawnMyPlayer()
 {
     Debug.Log("SpawnMyPlayer");
     PhotonNetwork.Instantiate("Airplane", Vector3.zero, Quaternion.identity, 0);
 }
Esempio n. 11
0
 private void DoInstantiate()
 {
     store.Value = PhotonNetwork.Instantiate(prefabName.Value, FsmUtility.GetPosition(target, position), target.Value != null && euler.IsNone?target.Value.transform.rotation:Quaternion.Euler(euler.Value), (byte)group.Value);
 }
Esempio n. 12
0
 public void Shoot(Vector3 direction)
 {
     PhotonNetwork.Instantiate(bullet.name, transform.position, Quaternion.LookRotation(direction, Vector3.up));
 }
Esempio n. 13
0
    public void meNembak()
    {
        GameObject bullet;

        bullet = PhotonNetwork.Instantiate(projectilePrefab.name, bulletSpawn.position, Quaternion.identity);
    }
Esempio n. 14
0
    public override void OnJoinedRoom()
    {
        Debug.Log("OnJoinedRoom");

        PhotonNetwork.Instantiate("player", Vector3.zero, Quaternion.identity, 0);
    }
Esempio n. 15
0
    public void Shoot(FiringPoint Point, int Index)
    {
        EmmisionMode Emmision  = Point.Emmision;
        ShotMode     Shooting  = Point.Shooting;
        ParticleMode Particles = Point.Particles;
        SoundMode    Sound     = Point.Sound;

        Vector3 ShootPosition = this.transform.position + this.transform.TransformDirection(Vector3.forward);

        switch (Emmision.Positioning)
        {
        case ShotPositioning.Direct:
            ShootPosition = this.transform.position + this.transform.forward;
            break;

        case ShotPositioning.Weapon1:
            ShootPosition = Weapons.ElementAt(0).position + this.transform.forward;
            break;

        case ShotPositioning.Weapon2:
            ShootPosition = Weapons.ElementAt(1).position + this.transform.forward;
            break;

        case ShotPositioning.Split:
            int CurrentWeapon = SplitFiringSelection.ElementAt(Index);
            ShootPosition = Weapons.ElementAt(CurrentWeapon).position + this.transform.forward;
            switch (CurrentWeapon)
            {
            case 0:
                SplitFiringSelection[Index] = 1;
                break;

            case 1:
                SplitFiringSelection[Index] = 0;
                break;
            }
            break;
        }
        if (Emmision.EmmisionRandomOffset != Vector3.zero && Emmision.EmmisionRandomOffset != null)
        {
            ShootPosition.x += Random.Range(-Emmision.EmmisionRandomOffset.x, Emmision.EmmisionRandomOffset.x);
            ShootPosition.y += Random.Range(-Emmision.EmmisionRandomOffset.y, Emmision.EmmisionRandomOffset.y);
            ShootPosition.z += Random.Range(-Emmision.EmmisionRandomOffset.z, Emmision.EmmisionRandomOffset.x);
        }

        Vector3    ParticlesPosition = Emmision.EmmisionOffset + Particles.Position;
        Quaternion ShootRotation     = this.transform.rotation * Quaternion.Euler(Emmision.RotationOffset);

        if (Particles.HasParticles == true)
        {
            Vector3 ParticleColor = new Vector3(Particles.Coloring.r, Particles.Coloring.g, Particles.Coloring.b);
            PhotonNetwork.RPC(this.photonView, "PlayParticles", RpcTarget.AllBuffered, false, ParticleColor,
                              Particles.Prefab, Particles.Type, ParticlesPosition, ShootRotation, Index, Particles.Size);
        }


        if (Sound != null && Time.time > NextTimeToPlaySound)
        {
            AudioSource Source = this.GetComponent <AudioSource>();
            Source.PlayOneShot(Sound.Clip, Sound.Volume);
            NextTimeToPlaySound = Time.time + Sound.Refresh;
        }

        for (int i = 0; i < Shooting.ShotCount; i++)
        {
            /*
             * EmmisionType EmitType = Emmision.Type;
             * RaycastHit Hit;
             * var dir = Quaternion.Euler(Emmision.RotationOffset) * this.transform.forward;
             * Debug.DrawRay(ShootPosition, dir, Color.cyan);
             *
             * switch (EmitType)
             * {
             *  case EmmisionType.Line:
             *      if (Physics.Raycast(ShootPosition, dir, out Hit, Shooting.Range, ~(1 << LayerMask.NameToLayer("Pieces"))))
             *      {
             *          Damage(Hit, Shooting, Index);
             *      }
             *      break;
             *  case EmmisionType.Tube:
             *      if (Physics.SphereCast(ShootPosition, Emmision.EmmisionSize, dir, out Hit, Shooting.Range, ~(1 << LayerMask.NameToLayer("Pieces"))))
             *      {
             *          Damage(Hit, Shooting, Index);
             *      }
             *
             * break;
             * }
             */

            //Quaternion dir = Quaternion.Euler(Quaternion.Euler(Emmision.RotationOffset) * this.transform.forward);
            Quaternion dir        = this.transform.rotation * Quaternion.Euler(Emmision.RotationOffset);
            GameObject projectile = PhotonNetwork.Instantiate(Emmision.Prefab, ShootPosition, dir);
            projectile.layer = LayerMask.NameToLayer("Bullets");
            projectile.transform.SetParent(GameObject.Find("TempStorage").transform);
            projectile.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
            PhotonNetwork.RPC(photonView, "SetProjectile", RpcTarget.AllBuffered, false, projectile.gameObject.GetPhotonView().ViewID,
                              this.gameObject.GetPhotonView().ViewID, new Vector3(Particles.ProjectileColor.r, Particles.ProjectileColor.g, Particles.ProjectileColor.b));
            projectile.GetComponent <Renderer>().sharedMaterial.color = Particles.ProjectileColor;

            Bullet b = projectile.AddComponent <Bullet>();
            b.shooter  = this.transform;
            b.Shooting = Shooting;
            b.index    = Index;
            b.speed    = Shooting.Speed;
            b.maxRange = Shooting.Range;
            b.force    = Shooting.Force;
            b.Fire();
        }

        NextTimesToFire[Index] = Time.time + (1 / Shooting.FireRate) + Shooting.Recharge;
        if (NextTimesToFire[Index] == Mathf.Infinity || NextTimesToFire[Index] == Mathf.NegativeInfinity)
        {
            NextTimesToFire[Index] = 0;
        }
    }
Esempio n. 16
0
 void CreateController()
 {
     PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerController"), new Vector3(369, 1, 500), Quaternion.identity);
 }
Esempio n. 17
0
 public void Spawn(string prefabName, Transform spawn) //REMEMBER TO SUMMARY THIS LATER
 {
     PhotonNetwork.Instantiate(prefabName, spawn.position, spawn.rotation, 0);
 }
        /// <summary>
        /// Setup the LocalPlayer instance whenever setupVR has been setup again
        /// </summary>
        /// <param name="info"></param>
        private void LocalPlayerSetup(OnSetupVRReady info)
        {
            if (_playersPrefab == null)
            {
                Debug.LogError("<b><Color=Red>[VRSF] :</b></Color> Missing playerPrefab Reference, can't refresh local player.", gameObject);
            }
            else
            {
                Debug.LogFormat("<b>[VRSF] :</b> We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName);
                RefreshLocalPlayer();
            }

            /// <summary>
            /// Setup the LocalPlayer instance Transform
            /// </summary>
            void RefreshLocalPlayer()
            {
                // Check if there's no more instance of the LocalPlayer
                if (VRSFBasicPlayersManager.LocalPlayerInstance != null)
                {
                    PhotonNetwork.Destroy(VRSFBasicPlayersManager.LocalPlayerInstance);
                }

                // Set the CameraRig pos and rot based on the previous check
                VRSF_Components.CameraRig.transform.position = _localPlayerPosCache;
                VRSF_Components.CameraRig.transform.rotation = _localPlayerRotCache;

                // Instantiate the loacalPlayer Instance
                VRSFBasicPlayersManager.LocalPlayerInstance = PhotonNetwork.Instantiate(PlayerPrefabName, _localPlayerPosCache, _localPlayerRotCache);

                // Add the follower scripts for the Camera, RightController and LeftController
                AddFollowerScript(VRSFBasicPlayersManager.LocalPlayerInstance, VRSF_Components.VRCamera.transform);
                TryGetObjectWithName("RightController", VRSF_Components.RightController.transform);
                TryGetObjectWithName("LeftController", VRSF_Components.LeftController.transform);

                /// <summary>
                /// Try to fetch an object under the LocalPlayerInstance using a name. If found, we add a FollowerScript to it.
                /// </summary>
                void TryGetObjectWithName(string objectName, Transform toFollow)
                {
                    var toLookFor = VRSFBasicPlayersManager.LocalPlayerInstance.transform.Find(objectName);

                    if (toLookFor == null)
                    {
                        Debug.LogErrorFormat("<b>[VRSF] :</b> Couldn't find object with name {0} under the Player prefab. Not adding any Follower Script.", objectName);
                    }
                    else
                    {
                        AddFollowerScript(toLookFor.gameObject, toFollow);
                    }
                }

                /// <summary>
                /// Add a VRSFTransformFollower to the transToFollow object, so it can follow the position and rotation of the toFollow object
                /// </summary>
                void AddFollowerScript(GameObject transToFollow, Transform toFollow)
                {
                    VRSFTransformFollower transFollower = transToFollow.AddComponent <VRSFTransformFollower>();

                    transFollower.ToFollow = toFollow;
                }
            }
        }
 public override void OnJoinedRoom()
 {
     PhotonNetwork.Instantiate("Player", new Vector2(Random.Range(-4f, 4f), transform.position.y), Quaternion.identity);
 }
Esempio n. 20
0
 public static GameObject NetworkEnable(string name, Vector3 position, Quaternion rotation, int group = 0)
 {
     return(PhotonNetwork.Instantiate(name, position, rotation, group));
 }
Esempio n. 21
0
 public override void OnJoinedRoom()
 {
     base.OnJoinedRoom();
     PhotonNetwork.Instantiate("Network Player", transform.position, transform.rotation);
 }
Esempio n. 22
0
 public void SpawnBeachMapDelay()
 {
     PhotonNetwork.Destroy(GameObject.FindWithTag("Map"));
     PhotonNetwork.Instantiate(BeachMap.name, new Vector3(0f, 7f, 17.18244f), Quaternion.identity, 0);
 }
Esempio n. 23
0
 private void CreateUser()
 {
     PhotonNetwork.Instantiate(Path.Combine("Prefabs", "User"), Vector3.zero, Quaternion.identity);
     groupManager.SetUpGroups();
 }
Esempio n. 24
0
 public void SpawnSnowMapDelay()
 {
     PhotonNetwork.Destroy(GameObject.FindWithTag("Map"));
     PhotonNetwork.Instantiate(SnowMap.name, new Vector3(-30f, -10f, 40f), Quaternion.identity, 0);
 }
Esempio n. 25
0
 void SummonTurret()
 {
     PhotonNetwork.Instantiate("Prefabs/Turret", localSkillComponent.gameObject.transform.position + new Vector3(3.0f, 0f, 0f), Quaternion.identity, 0);
 }
Esempio n. 26
0
 public void CreateInteractiveCube()
 {
     var objectToInstanciate = PhotonNetwork.Instantiate(interactiveObjectToInstanciate.name, transform.position, transform.rotation, 0);
 }
Esempio n. 27
0
 void Awake()
 {
     PhotonNetwork.Instantiate(PlayerPref.name, new Vector3(5, -0.05f, -26), Quaternion.identity);
 }
Esempio n. 28
0
    [PunRPC] public void PlayParticles(Vector3 ParticlesColor, string ParticlesName, string ParticlesType, Vector3 ParticlesPosition, Quaternion ParticlesRotation, int ParticlesIndex, float Size)
    {
        GameObject ParticleObject = null;
        Color      Coloring       = new Color(ParticlesColor.x, ParticlesColor.y, ParticlesColor.z);

        if (ParticlesType == "LineRenderer")
        {
            GameObject   Line = null;
            LineRenderer l    = null;
            if (!this.transform.Find("Line: " + ParticlesIndex.ToString()))
            {
                Line = new GameObject();
                Line.transform.name = "Line: " + ParticlesIndex.ToString();
                Line.transform.SetParent(this.transform);
                Line.transform.localPosition = Vector3.zero;
                Line.transform.localRotation = Quaternion.Euler(Vector3.zero);
                l          = Line.AddComponent <LineRenderer>();
                l.material = Resources.Load <Material>("Materials/Particle/LineMaterial");
            }
            else
            {
                Line = this.transform.Find("Line: " + ParticlesIndex.ToString()).gameObject;
                l    = Line.GetComponent <LineRenderer>();
            }
            l.enabled = true;
            SetLinePositions(l, this.transform.position, this.transform.position + (this.transform.forward * Weapon.Points[ParticlesIndex].Shooting.Range));
            StopCoroutine("ShrinkLineRenderer");
            StartCoroutine(GrowLineRenderer(l, Size, 0.25f, Coloring));
        }
        else
        {
            if (!this.transform.Find("Particles" + ParticlesIndex.ToString()))
            {
                ParticleObject = PhotonNetwork.Instantiate("Particles/" + ParticlesName, this.transform.position, ParticlesRotation, 0);
                ParticleObject.transform.SetParent(this.transform);
                ParticleObject.transform.localPosition = ParticlesPosition;
                ParticleObject.transform.localScale    = new Vector3(Size, Size, Size);
                ParticleObject.transform.name          = "Particles" + ParticlesIndex.ToString();

                if (ParticlesType == "ParticleSystem")
                {
                    var Main = ParticleObject.GetComponent <ParticleSystem>().main;
                    Main.startColor = Coloring;
                }

                if (ParticlesType == "KvantSprayMV")
                {
                }

                if (ParticlesType == "KvantSwarmMV")
                {
                }
            }
            else
            {
                ParticleObject = this.transform.Find("Particles" + ParticlesIndex.ToString()).gameObject;
                ParticleObject.SetActive(true);

                if (ParticlesType == "ParticleSystem")
                {
                    ParticleObject.GetComponent <ParticleSystem>().Play();
                }
                if (ParticlesType == "KvantSprayMV")
                {
                    ParticleObject.GetComponent <Kvant.SprayMV>().throttle = 1;
                }
                if (ParticlesType == "KvantSwarmMV")
                {
                    ParticleObject.GetComponent <Kvant.SwarmMV>().throttle = 1;
                    RaycastHit hit;
                    if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, 100, ~(1 << LayerMask.NameToLayer("Bullets"))))
                    {
                        float   dist   = Vector3.Distance(this.transform.position + this.transform.forward, hit.transform.position);
                        float   z      = dist * 0.125f;
                        Vector3 vector = new Vector3(0f, 0f, z);
                        ParticleObject.GetComponent <Kvant.SwarmMV>().flow = vector;
                    }
                }
            }
        }
    }
 private void CreateMortar()
 {
     Debug.Log("Loading Player.");
     PhotonNetwork.Instantiate(Path.Combine("Prefabs", "MortarTankPref"), Vector3.up * 10, Quaternion.identity);
 }
 public override void OnJoinedRoom()
 {
     Debug.Log("join room");
     // マッチング後、自分自身のネットワークオブジェクトを生成する
     PhotonNetwork.Instantiate(obj.name, Vector3.zero, Quaternion.identity);
 }