So guys I have a game where whenever a player picks up an item, it calls a function that cycles throw an array of scriptableobjects of power buttons similar to when mystery box in Maria Kart. Here is the code on the playermovement.cs script:
public virtual void OnCollisionEnter(Collision collision)
{
if (view.IsMine)
{
/*Player * is Ground or the tiles*/
if (collision.gameObject.layer == 8)
{
isJumping = false;
AddLocalScore();
}
/*If online player hits an special items*/
if (collision.gameObject.layer == 13)
{
/*Call Item Effect and disable item*/
collision.gameObject.GetComponent<Item>().CallOnlineCoroutine();
OnlineManager.Instance.CollidedWithItem(view);
print(PhotonNetwork.NickName);
print(view.ViewID);
}
}
}
And here is the code that handles cycling of power buttons. It is from script called OnlineManager.cs :
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class OnlineManager : MonoBehaviour
{
public GameObject player;
public float minX, minZ, MaxX, MaxZ;
public Canvas canvas;
public Text FakeSoreText;
public Camera player_camera;
public Vector3 offset;
private Vector3 RespawnPosition;
private int score;
private PhotonView view;
private PhotonView PowerButtonview;
private static OnlineManager _instance;
private int player_index;
[Header("PowerButtons")]
public PowerButtonsData[] powerButtonsData; //array that holds the powerUp scriptable object
public PowerButtonController p_ButtonController;
Button DisplayedGameButton;
public float count = 30f;
private WaitForSeconds delay = new WaitForSeconds(1f);
public Button buttonTexture;
public PowerButtonsData powerButtonData;
private AudioManager audioManager;
private string audiostring = "Special";
public static OnlineManager Instance
{
get
{
if (_instance == null)
{
GameObject Obj = new GameObject("Online Manager");
Obj.AddComponent<OnlineManager>();
}
return _instance;
}
}
private void Awake()
{
_instance = this;
}
void Start()
{
Vector3 randomPosition = new Vector3(Random.Range(minX, MaxX), 10, Random.Range(minZ, MaxZ));
/*Creates player online*/
GameObject LocalPlayer = PhotonNetwork.Instantiate(player.name, randomPosition, Quaternion.identity);
/*Updates score on player when they walk on falling platform*/
PlayerMovement.OnStep += AddScore;
view = GetComponent<PhotonView>();
/*Power BUtton Photon View*/
PowerButtonview = GetComponent<PhotonView>();
audioManager = Manager.Instance.GetAudioManager;
}
/*Called by online players after falling*/
public Vector3 RandomRespawnPosition()
{
RespawnPosition = new Vector3(Random.Range(minX, MaxX), 10, Random.Range(minZ, MaxZ));
return RespawnPosition;
}
public void AddScore()
{
view.RPC("AddScoreRPC", RpcTarget.All);
}
[PunRPC]
void AddScoreRPC()
{
score++;
}
public void CollidedWithItem(PhotonView playerView)
{
StartCoroutine(ShufflePowerUps(playerView));
}
public IEnumerator ShufflePowerUps(PhotonView playerView)
{
if (playerView.IsMine)
{
audioManager.Play(audiostring);
count = 30f;
PowerButtonsData p_Buttondata;
p_ButtonController.gameObject.transform.localScale = new Vector3(1, 1, 1);
while (count != 0)
{
count--;
p_Buttondata = powerButtonsData[Random.Range(0, powerButtonsData.Length)];
EvaluatePowers(p_Buttondata);
yield return delay;
p_Buttondata = powerButtonsData[Random.Range(0, powerButtonsData.Length)];
EvaluatePowers(p_Buttondata);
}
StopCoroutine(ShufflePowerUps(playerView));
p_ButtonController.gameObject.transform.localScale = new Vector3(0, 0, 0);
}
}
public void EvaluatePowers(PowerButtonsData PBD)
{
/*Assigns the power data*/
powerButtonData = PBD;
buttonTexture.image.sprite = powerButtonData.GetIcon;
}
}
So basically the script works well on host player player collides with the item gameObject but other players on the network does see this piece of code " p_ButtonController.gameObject.transform.localScale = new Vector3(1, 1, 1)" working when they collide with the item