- Home /
Photon multiplayer game working in editor but not in build.
There are two problems I appear to be having at once.
Problem #1: I made a script to scatter gameobjects throughout a set radius, and it works beautifully in the editor, but does absolutely nothing in the build. If I start a photon room in the editor, and then join it in a build, however, the objects will be there in the world, but if I start a room in the build they simply do not spawn. Here is the script:
using UnityEngine;
using System.Collections;
public class SpawnItems : MonoBehaviour {
public GameObject Item;
public int spawnNum = 12;
public int negX = -155;
public int posX = 155;
public int negZ = -155;
public int posZ = 155;
void spawn()
{
for(int i = 0; i <spawnNum; i++)
{
Vector3 ItemPos = new Vector3(this.transform.position.x + Random.Range(negX, posX), this.transform.position.y + Random.Range(0.0f, 0.0f), this.transform.position.z + Random.Range(negZ, posZ));
GameObject ItemGO = (GameObject)PhotonNetwork.Instantiate(Item.gameObject.name,ItemPos,Quaternion.identity, 0); //PhotonNetwork.
}
}
// Use this for initialization
void OnCreatedRoom()
{
spawn();
}
// Update is called once per frame
void Update () {
}
}
Problem #2: I also made a (totally unrelated) script which is placed on an object so that it would move along the Terrain at a raycast hit sent from the center of the player's view. It was meant to be a building system, like in games like rust, where a transparent preview of an object being built exists where the object will be placed, then, when the player clicks, it spawns the object in its place. Again, it works like a charm, but only in the editor. In the built edition of the game, the ghost object (the preview) does not move at all. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlaceThingC : MonoBehaviour {
public Transform prefab;
public float speed = 1.0f;
public Camera PlayerCamera;
void Start (){
}
void Update (){
Ray ray = PlayerCamera.ScreenPointToRay(Input.mousePosition); //camera.main.ScreenPointToRay
RaycastHit hit;
Vector3 euler = this.transform.rotation.eulerAngles; //Quaternion.Euler(this.transform.rotation.x, this.transform.rotation.y, this.transform.rotation.z);
if (Physics.Raycast(ray, out hit,Mathf.Infinity)) {
if(hit.collider.tag == "Terrain"){
if (Input.GetKey(KeyCode.E)) {
transform.Rotate(Vector3.up * speed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.Q)) {
transform.Rotate(-Vector3.up * speed * Time.deltaTime);
}
transform.position = hit.point;
if (Input.GetMouseButtonDown(0)) {
PhotonNetwork.Instantiate (prefab.gameObject.name, hit.point, Quaternion.Euler(euler.x,euler.y,euler.z), 0);
this.transform.gameObject.SetActive(false);
}
}
}
}
[PunRPC]
void Test (){}
}
Thanks in advance to anyone who bothers to help me out here.
Answer by Nicolas4677 · Nov 19, 2018 at 09:08 PM
Het, did you get a solution? I'm having same error.
Your answer
Follow this Question
Related Questions
Setting different values on editor and build 1 Answer
Distribute terrain in zones 3 Answers
Discrepancy Between Editor and Build World Transform Positions 1 Answer
How to sync child objects of a transform in multiplayer 3 Answers
Materials breaking in built project (but not in editor play mode) 0 Answers