0
Answered

Change Camera Target by programmatically

efekanpulatli 6 months ago in Melee updated by Marti (Lead Developer) 6 months ago 5

I want to change camera target to different target by programmatically or by using something else,i want to change it dynamically while game running.

how can i do that?

Unity version:
2018
Game Creator version:
1.1.6

Answer

+1
Answer

This is a question related to how the Photon Network works, which I have very little experience with. Once you get the instantiated game object, simply store it in a temporal global variable by doing:

First create a global variable called "spawn-point" of type Game Object.

Then, use the following line to save the instantiated game object into the global variable:

VariablesManager.Instance.SetGlobal("spawn-point", yourGameObjectInstance);

Now that your reference is stored, you can use it to change the camera's target, using the Target Camera Action and set the "Look At" field to Global Variable and select the "spawn-point" option.

What you'll need to look for is how to get the instance of the prefab using Photon Network, but shouldn't be difficult.

BAD, I'M UNSATISFIED

What if gameobject created by using instantiate function that are belong to GameObject Static function after game started?

https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

How can i assign this variable to target?

Satisfaction mark by efekanpulatli 6 months ago
Answered

You can use the Target Camera Motor Action. You can specify the target and anchor fields there based on a Local/Global/List Variable, which can be dynamically set.

When you use the Instantiate Action from Game Creator, you have the option to store a reference to this new object in a Local/List/Global Variable. Which can be used to set the target.

How can i do that by using GC ? 

myView = PhotonNetwork.Instantiate("Player",GameObject.Find(spawnPoint).transform.position,GameObject.Find(spawnPoint).transform.rotation).GetComponent<PhotonView>();

+1
Answer

This is a question related to how the Photon Network works, which I have very little experience with. Once you get the instantiated game object, simply store it in a temporal global variable by doing:

First create a global variable called "spawn-point" of type Game Object.

Then, use the following line to save the instantiated game object into the global variable:

VariablesManager.Instance.SetGlobal("spawn-point", yourGameObjectInstance);

Now that your reference is stored, you can use it to change the camera's target, using the Target Camera Action and set the "Look At" field to Global Variable and select the "spawn-point" option.

What you'll need to look for is how to get the instance of the prefab using Photon Network, but shouldn't be difficult.

Yes,I guess this will solve my problem