How to update variables on an object via their photonView ID
Options
I was to create an PunRPC that broadcasts a photonview id and some variable updates.
I can't work out how to convert a photonview reference into something where I can see the attached game objects variables to edit.
The game object has public variables I want to update (floats and bools)
My last attempt was:
I can't work out how to convert a photonview reference into something where I can see the attached game objects variables to edit.
The game object has public variables I want to update (floats and bools)
My last attempt was:
[PunRPC]
public void AIAttack(int enemy)
{
PhotonView target = PhotonView.Find(enemy);
// This is not seen as a valid variable to update
target.gameObject.dead = true;
0
Best Answer
-
Hi,
you need to get the component on the GameObject, you can not access a public property of a component attached to a GameObject without first getting the component itself using target.gameobject.getComponent()
Bye,
Jean
5
Answers
-
Hi,
you need to get the component on the GameObject, you can not access a public property of a component attached to a GameObject without first getting the component itself using target.gameobject.getComponent()
Bye,
Jean
5 -
[PunRPC] public void AIAttack(int enemy) { PhotonView target = PhotonView.Find(enemy); // This finds the network id gameobject and script containing variable to change target.gameObject.GetComponent<EnemyLogic>().dead = true; }
Thanks!
Here's a sample of the working code0