我遇到的问题是,在玩家赶上它之后相机中的所有精灵都会消失,但所有精灵在场景视图中仍然可见?我相机的代码是
using UnityEngine;
using System.Collections;
public class CamMovement : MonoBehaviour {
public Transform target;
public float speed;
public bool M;
void Start () {
}
void Update () {
if (M == true) {
transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
}
void OnTriggerEnter2D (Collider2D C){
if (C.gameObject.tag == "Player") {
M = false;
}
}
void OnTriggerExit2D (Collider2D C){
if (C.gameObject.tag == "Player") {
M = true;
}
}
}
谢谢,我将不胜感激任何帮助:)
答案 0 :(得分:0)
我假设您将目标设置为等于您的玩家对象。 The camera clips near and far by default,因此相同z级别的对象不会显示在相机上。
像这样更改你的代码,以便它在z轴上保持足够远,它应该可以工作:
transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.position.x, target.position.y, transform.position.z), speed * Time.deltaTime);