Search Unity

Question Why Don't It Work.

Discussion in 'Scripting' started by SealBarkStudios, Aug 18, 2022.

  1. SealBarkStudios

    SealBarkStudios

    Joined:
    May 21, 2022
    Posts:
    19
    This Is For My Game With The Building Tools. I Have A Feature Where You Can Change The Color And Texture Of An Object. However It Only Works For Your Client And Not Other Peoples Clients. Here Is My Script I'm Using.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using Photon.Pun;
    using Photon.Realtime;

    public class _script3again : MonoBehaviourPunCallbacks
    {
    public float R = 0f;
    public float G = 0f;
    public float B = 0f;
    public float A = 0f;
    public Sprite customtext;
    public Sprite grasstext;
    public Sprite dirttext;
    public Sprite stonetext;
    public Sprite sandtext;
    public Sprite bricktext;
    public Sprite planktext;
    public Sprite custombricktext;
    public PhotonView photonViewer;
    public SpriteRenderer sprite;
    void Start()
    {
    sprite = GetComponent<SpriteRenderer>();
    }
    void Update()
    {
    // fix all this code
    }
    [PunRPC]
    public void OnMouseDown()
    {
    if (_script3.buildtype == 2)
    {
    PhotonNetwork.Destroy(gameObject);
    }
    if (_script3.buildtype == 3)
    {
    photonView.RPC("Color", Photon.Pun.RpcTarget.AllBuffered);
    }
    }

    [PunRPC]
    public void Color()
    {
    R = GameManager.Red;
    G = GameManager.Green;
    B = GameManager.Blue;
    sprite.color = new Color(R, G, B);
    if (GameManager.TextureFloat == 0)
    {
    sprite.sprite = customtext;
    }
    if (GameManager.TextureFloat == 1)
    {
    sprite.sprite = grasstext;
    }
    if (GameManager.TextureFloat == 2)
    {
    sprite.sprite = dirttext;
    }
    if (GameManager.TextureFloat == 3)
    {
    sprite.sprite = stonetext;
    }
    if (GameManager.TextureFloat == 4)
    {
    sprite.sprite = sandtext;
    }
    if (GameManager.TextureFloat == 5)
    {
    sprite.sprite = bricktext;
    }
    if (GameManager.TextureFloat == 6)
    {
    sprite.sprite = planktext;
    }
    if (GameManager.TextureFloat == 7)
    {
    sprite.sprite = custombricktext;
    }
    }
    }

    I Know I Have Posted Here Several Times But I Don't Know What I'm Doing Sometimes. Please Help I Need This Version Done In 3 Days. Thanks.
    If I Don't Have This Version Done In 3 Days My Boss Is Gonna Hit Me With A Cast Iron Pot.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Is everything you have done above reasonable considering what Bunny83 has already posted to you about RPCs and multiplayer?

    https://forum.unity.com/threads/what-does-this-mean.1319349/#post-8342883

    Also, just FYI, you are not using the correct code formatting so there are no line numbers and thus nobody can draw your attention to any particular part of your code.

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  3. SealBarkStudios

    SealBarkStudios

    Joined:
    May 21, 2022
    Posts:
    19
    ok thanks