1 using UnityEngine; 2 using System.Collections; 3 4 public class FollowBird : MonoBehaviour { 5 private GameObject bird; 6 private Transform birdTransform; 7 8 // Use this for initialization 9 void Start () { 10 bird = GameObject.FindWithTag("Player"); 11 birdTransform = bird.transform; 12 } 13 14 // Update is called once per frame 15 void Update () { 16 Vector3 birdPosition = birdTransform.position; 17 //保证摄像机中不出现游戏外的场景 18 float cam_y = birdPosition.y - 1.1148f; //摄像机的y 19 if (cam_y > 1.6f) 20 cam_y = 1.6f; 21 if (cam_y < -1.5f) 22 cam_y = -1.5f; 23 24 this.transform.position = new Vector3(birdPosition.x + 2.22084f, 25 cam_y, birdPosition.z - 13.917f); 26 } 27 }
时间: 2024-10-06 17:13:13