¿Open a door with an item?

Good day to everyone, Im starting with Photon on Unity and Im having a question:
I create an item and the idea is, when the player pick up the item, a var must be sent to the door to change a bool var from false to true, so the player can open it.
I use in the item: (ScriptName).Var = true; // The door script have a public static bool var = false;
all works (the object pickup, the sound, effect, but no the bool never change.
The door work perfect if i do not use this bool value (If I have a door with no key)

Anyone knows what can i do?

Thanks in advance!

Best Answer

Answers

  • Do you exactly change the bool of the door?
  • I want to change the bool in the door from false to true on the key item, but its not working

    If you want i can share the code
  • Yes, because by your words all should work.
  • Here is the code:

    -----------------------------------
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    [RequireComponent(typeof(PhotonView))]

    public class Key1 : bl_PhotonHelper
    {

    private PhotonView view = null;
    public bool m_Into = false;
    private bool open = false;


    void Awake()
    {
    view = PhotonView.Get(this);

    }


    [PunRPC]
    public void Key1Event()
    {
    open = true;
    }


    void OnTriggerEnter(Collider c)
    {
    if (c.transform.tag == bl_PlayerPhoton.PlayerTag)
    {
    bl_PlayerPhoton p = c.GetComponent();
    if (p.isLocalPlayer)
    {
    m_Into = true;
    }
    }
    }

    void OnTriggerExit (Collider c)
    {
    if (c.transform.tag == bl_PlayerPhoton.PlayerTag)
    {
    bl_PlayerPhoton p = c.GetComponent();
    if (p.isLocalPlayer)
    {
    m_Into = false;
    }
    }
    }

    void SyncKey()
    {
    view.RPC("Key1Event", PhotonTargets.OthersBuffered);
    }


    void Update ()
    {

    if (Input.GetKeyDown(KeyCode.G) && m_Into )
    {
    SyncKey();
    Key1Event();
    }

    if(open)
    {
    DoorCRotKey1.KEY1 = true;
    }




    }


    }
    -----------------------------------


    Thanks in advance!!
  • Dmitry
    Dmitry
    edited March 2016
    I don't see anything wrong. Maybe try to put some Debugs to your code and find function where the problem starts. And check your variable "IsLocalPlayer". If I understood right, it's your own class, so there can be some mistakes.
  • But in the door the IsLocalPlayer variable works perfect :(
  • I manage to find the problem. The code I share is correct as you say before. The problem comes with another script.
    Thx Dmitry!