- Home /
How do I make a camera look for a specific GameObject while networking?
Hi! I just fixed with networking and now I've finally been able to connect myself up globally. However, there's a problem. I have no idea, whatsoever how I will get a specific instantiated camera to follow a specific instantiated gameobject. I am using the camerafollow script as following:
using UnityEngine; using System.Collections; public class SmoothCam : MonoBehaviour { public float mFollowRate = 1f; public float mFollowHeight = 20f; public Transform target; void Start(){ if(!networkView.isMine) enabled = false; } void LateUpdate () { if(networkView.isMine) transform.position = Vector3.Lerp( transform.position, target.position + new Vector3(0f, (mFollowHeight - target.position.y), 0f), Time.deltaTime * mFollowRate); } }
So. Exactly how will I make my specific camera, when instantiated follow the specific instantiated GameObject?
Ok. I just though because you didn't reply to $$anonymous$$OLB in any way. Normaly you would say what didin't work for you or if you get any error messages or something like this.
Answer by MOLB · Mar 23, 2013 at 08:24 AM
This might be what you're looking for.
foreach(Camera cam in GameObject.FindObjectsOfType(typeof(Camera)))
{
if(cam.tag == "myTag" && cam.networkView.isMine == true)
{
target = cam;
Debug.Log("Target is set to: " + cam.name);
}
}
This has worked for me in the past.
Your answer
Follow this Question
Related Questions
Camera Smooth Follow 2 Answers
smooth follow 2d camera runner ios 0 Answers
follow camera is jerky for other objects 1 Answer
How can I get my camera to reset its position behind the player? 1 Answer
Modified SmoothFollow 0 Answers