SimpleFollow.cs 767 Bytes
using UnityEngine;
using System.Collections;

public class SimpleFollow : MonoBehaviour
{
    public Transform target;
    public bool followX;
    public bool followY;
    public bool followZ;

    private Vector3 _follow;
    private Vector3 _startPos;

    void Start ()
    {
        _follow = Vector3.zero;

        if (followX)
            _follow += Vector3.right;
        if (followY)
            _follow += Vector3.up;
        if (followZ)
            _follow += Vector3.forward;

        _startPos = transform.position;
	}
	
	void LateUpdate ()
    {
        Vector3 followPos = new Vector3(target.position.x * _follow.x, target.position.y * _follow.y,
            target.position.z * _follow.z);
        transform.position = _startPos + followPos;
	}
}