This code is supposed to generate new food in random positions over the network when the player eats the current one. The code runs smoothly on master client but it's kinda slow on other players.
Any idea what am i doing wrong?
using UnityEngine;
using System.Collections;
public class FoodCollision : Photon.MonoBehaviour
{
public static float amtOfIncreaseSpeed = 1f;
public static float amtOfIncreaseHealth = 1f;
public static float ratioOfSpeed = 150.0f;
public static float increaseSize = 0.001f;
PhotonView photonView;
BoxCollider2D boxCollider;
SpriteRenderer sp;
float widthOfBoard, heightOfBoard;
void Awake()
{
photonView = PhotonView.Get(this);
boxCollider = GetComponent<BoxCollider2D>();
sp = GetComponent<SpriteRenderer>();
widthOfBoard = FoodManager.instance.widthOfBoard;
heightOfBoard = FoodManager.instance.heightOfBoard;
}
public void ResetGO()
{
sp.enabled = false;
photonView.RPC("ResetGORPC", PhotonTargets.AllBuffered);
}
[PunRPC]
void ResetGORPC()
{
Vector3 position = new Vector3(Random.Range(-widthOfBoard / 2, widthOfBoard / 2), Random.Range(-heightOfBoard / 2, heightOfBoard / 2), 0);
transform.position = position;
transform.localScale = Vector3.one;
sp.enabled = true;
}
}