get player object in scene

Options
hi! i make fps game. I have a problem. I need to make a spawn shield but I can't do anything. I have a player on the disabled object, "the shield". I need to turn it on, when a player appears for 3 seconds. I did everything: timer function enable, rpc. but one question: when performing rpc, I have to find the scene object with the player, but I don't know how. so I tried to do this:

IEnumerator stime()
{
shiled = 4;
while(shiled > 0)
{
shiled--;

ens ();

yield return new WaitForSeconds(1);
}

dis();
}

ens void()
{
photonView.RPC ("ensh", PhotonTargets.Others, PhotonNetwork.playerName);
}
void dis()
{
photonView.RPC ("dish", PhotonTargets.Others, PhotonNetwork.playerName);
}

[PunRPC]
void ensh(string name)
{
tar = GameObject.Find (name);
//Debug.Log (name);
star = tar.gameObject.transform.GetChild (4).gameObject;
//star = name.transform.GetChild (4).gameObject;
star.SetActive (true);
}

[PunRPC]
void dish(string name)
{
tar = GameObject.Find (name);
star = tar.gameObject.transform.GetChild (4).gameObject;
//star = name.transform.GetChild (4).gameObject;
star.SetActive (false);
}

he gave the name of the player. in the scene the player object with the same name as the name in the photon
«1

Answers

  • Grinch
    Options
    can you explain is this shield on the level or ?
  • AxReal
    Options
    no, on the player prefab
  • Grinch
    Options
    i do not get your code so you need to turn something for 4 second and then disable it ? something like this ?
  • AxReal
    Options
    ens void()
    {
    photonView.RPC ("ensh", PhotonTargets.Others, PhotonNetwork.playerName);
    }

    void ensh(string name)
    {
    tar = GameObject.Find (name);
    //Debug.Log (name);
    star = tar.gameObject.transform.GetChild (4).gameObject;
    //star = name.transform.GetChild (4).gameObject;
    star.SetActive (true);
    }
  • AxReal
    Options
    its screenshot
  • Grinch
    Options
    for example if you want to make some effect for yourself and for others to see this you can make something like this :
    void EnableEffect()
    {
    photonView.RPC("ShowEffect",PhotonTargets.All);
    }

    [PunRPC]
    void ShowEffect()
    {
    // here code for showing if the effect is same you can remove checking isMine
    if(photonView.isMine)
    {
    //for local player
    }
    else
    {
    //for other players too see this
    }
    }
  • Grinch
    Options
    you do not need to send player name its your player and your photon view and it will get all your copies
  • AxReal
    Options

    its screenshot of player prefab
  • AxReal
    Options
    but how i can activate object?
  • Grinch
    Options
    and disable function can be called in ShowEffect by calling Invoke();
  • Grinch
    Options
    transform.getchild(4).gameobject.setactive(true);
  • AxReal
    Options
    no! i want to enable shield on another player!
  • AxReal
    Options
    it`s enable shield on me, but other players can`t see it.
  • Grinch
    Options
    on copy of yourself in other players PC ?
  • Grinch
    Options
    the code that i have send will activate something on yourself locally and for your copy
  • AxReal
    Options

    its me on my client
  • AxReal
    Options


    but its me on another client
  • AxReal
    Options

    on another
  • Grinch
    Options
    can you make code that i wrote to set on some key down and you will see its working :)
  • AxReal
    Options
    on copy of yourself in other players PC ? yes, yes! i want to activate shield on my copy on other players pc
  • AxReal
    Options
    ok
  • AxReal
    Options
    but i need to enable shield on my copie localy?
  • Grinch
    Options
    [PunRPC]
    void ShowEffect()
    {
    gameobject.setactive(true);
    }

    this will activate on local and client
  • AxReal
    Options
    i`ll try it
  • AxReal
    Options
    nooo! not working
  • AxReal
    Options
    its activate shield locally, on my pc. but on other pc shield on my copie not activated
  • AxReal
    Options
    this.StopCoroutine ("stime");
    this.StartCoroutine ("stime");
    void ens()
    {
    photonView.RPC ("ensh", PhotonTargets.All);
    }
    void dis()
    {
    photonView.RPC ("dish", PhotonTargets.All);
    }

    IEnumerator stime()
    {
    shiled = 4;
    while(shiled > 0)
    {
    shiled--;
    print ("shild" + shiled);
    ens();

    yield return new WaitForSeconds(1);
    }

    dis();
    Debug.Log ("sh dis");

    }
    [PunRPC]
    void ensh()
    {
    //tar = GameObject.Find (name);
    //Debug.Log (name);
    //star = tar.gameObject.transform.GetChild (4).gameObject;
    //star = name.transform.GetChild (4).gameObject;
    //star.SetActive (true);
    ourPlayer.transform.GetChild(4).gameObject.SetActive(true);
    }

    [PunRPC]
    void dish()
    {
    //tar = GameObject.Find (name);
    //star = tar.gameObject.transform.GetChild (4).gameObject;
    //star = name.transform.GetChild (4).gameObject;
    //star.SetActive (false);
    ourPlayer.transform.GetChild(4).gameObject.SetActive(false);
    }
  • Grinch
    Options
    can you try AllBuffered
  • Grinch
    Options
    i will post Demo so you can see that everything is working
  • Grinch
    Options
    here is link
    https://www.dropbox.com/s/tyqaqifsiyr7uzl/DemoWorker.rar?dl=0
    replace this forlder in PUNs Unity folder. I have changed PlayerNetworkController look at Update function. everything is working only thing is if you want to notify players that join after you have disabled effect use AllBuffered when Calling RPC