- Home /
Tags not working
Im trying to get the scene camera to jump to a prefab clone when it spawns in with a tag. The tag is camerafollowme. I just use the tag drop down bar in the inspector for tagging.
My overall goal is to have each client their own camera so it ignores cameras not local if anyone knows that one?
Also the comments in the text are me fooling around to try to get it to work. :?
//Transform target;
//public GameObject[] target;
public float dampTime = 0.15f;
private Vector3 velocity = Vector3.zero;
public Transform target;
void Start () {
//target = GameObject.FindGameObjectWithTag ("camerafollowme").transform;
}
// Update is called once per frame
void Update ()
{
if (target)
{
Vector3 point = GetComponent<Camera>().WorldToViewportPoint(target.position);
Vector3 delta = target.position - GetComponent<Camera>().ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z)); //(new Vector3(0.5, 0.5, point.z));
Vector3 destination = transform.position + delta;
transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
}
}
}
Answer by OrbitGames · Jul 30, 2015 at 07:25 PM
It's not working because you aren't actually setting the target in the update function; add this line
target = GameObject.FindGameObjectWithTag ("camerafollowme").transform;
to the update function and you should be good.
Your answer
Follow this Question
Related Questions
How do I create a Camera and make it mainCamera with csharp script ? 1 Answer
Unity (5) Scene camera Clipping 3 Answers
Camera not showing in scene view 0 Answers
default setting scene area 1 Answer
Transform Rotation - Maths Problem 2 Answers