Here is my code. Help.
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public Transform TobyController; // Reference to the TobyController's transform.
void Awake ()
{
//Setting up the reference.
//TobyController = GameObject.FindGameObjectWithTag("TobyController").transform;
TobyController = GameObject.FindWithTag ("TobyController").transform;
}
void FixedUpdate ()
{
TrackTobyController();
}
void TrackTobyController ()
{
// By default the target x and y coordinates of the camera are it's current x and y coordinates.
float targetX = TobyController.position.x;
float targetY = TobyController.position.y;
// Set the camera's position to the target position with the same z component.
Vector3 v = new Vector3(targetX, targetY, transform.position.z);
transform.position = Vector3.Lerp(transform.position, v, Time.deltaTime);
}
}
By the way, I am making a simple ball rolling game and my balls name is Toby :^)