Setting camera script target to a photon network game object

I have a game object instantiated using photon network as so:

  GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerModel", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);

This script sits in a SCRIPT game object in my scene. ie,

I want to have my camera called “Camera” with the smoothfollow script setup as follows:

I basically want to set the target of the smooth follow script to the game object instantiated by Photon Network.

I’ve tried various variations of the code:

  GameObject.Find("Camera").GetComponent<SmoothFollow>().target = myPlayerGO;
  GameObject.Find("Camera").GetComponent("SmoothFollow").target = myPlayerGO;
  GameObject.Find("Camera").GetComponent(SmoothFollow).target = myPlayerGO;

But get various different errors not letting me do this. All the documentation and other forum posts i’ve found suggested that this code should work.

If someone could tell me what I’m doing wrong that would be great

Normally I would just have the camera part of the game object, but I’m using a script to make my gameobject turn towards my mouse, and it does funny thing with the camera.

Updated first post with pictures/more detailed info

What errors are you getting? It might be because you are attempting to access js from c#, which can cause issues because of compile order. Is SmoothFollow in Plugins or StandardAssets folder?

1 Like