Equivalent of instantiate in unity with photon

Options
Hello,
I'm actually making an agario clone for practice (sorry for the quote but the quote code doesn't work)

The situation is, i have my player prefab with view id, on my player i have my sphere without viw id as child of player.
When I push Spacebar, my spechere in my player become tow sphere with one half scale on the first sphere,
as if the sphere was divide in two little sphere.

So i divide the scale of the first sphere and instantiate a new sphere in the player.
The attack space script is on sphere object.

Here the code of unity offline version, how use RPC and instantiate in photon for have the equivalent, considering that the method in unity handle to instantiate in parent object directly :


if (Input.GetKeyDown(KeyCode.Space) && scalex > 2*data.initialScale)
{
data.isDivide = true;
transform.localScale = new Vector3(scalex / 2, scaley / 2, 0);
Vector3 Target = new Vector3(this.transform.position.x + 1, this.transform.position.y, 0);

GameObject newObject = Instantiate(Division, Target, Quaternion.identity, transform.parent);
newObject.transform.localScale = transform.localScale;
}


Comments

  • Hi @HotnCold,

    when changing the scale of the object you have to notify other clients about that change as well. You can either do this by using RPC calls or by adding the scale as an observed component to the PhotonTransformView component, which might be the easier way in this case, because the scale changes frequently. To instantiate a networked object you can use PhotonNetwork.Instantiate(...).

    If you are new to Photon, I would recommend you working through the Basics Tutorial which covers all necessary aspects you need for your game. If you have further questions, please feel free to ask.
  • HotnCold
    Options
    Think you for the anwser I already did the basic tutorial,
    Instantiate could be a solution as well, as I said, there are not transform .parent parameter in the photonnetwork instantiate function.
    And i would instantiate in the parent player the new space, because the attack space script is on the sphere.
    I would find a way to use isntantiate in my case.
    Thank you in advance.