相机追上玩家 Unity2D 后精灵消失
Sprites disappearing after camera catches up with player Unity2D
我遇到一个问题,在跟随玩家的相机追上游戏中的所有精灵后,所有精灵都消失了,但所有精灵在场景视图中仍然可见?我的相机的代码是
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;
}
}
}
谢谢,如果有任何帮助,我将不胜感激:)
我假设您将目标设置为等于您的播放器对象。 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);
我遇到一个问题,在跟随玩家的相机追上游戏中的所有精灵后,所有精灵都消失了,但所有精灵在场景视图中仍然可见?我的相机的代码是
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;
}
}
}
谢谢,如果有任何帮助,我将不胜感激:)
我假设您将目标设置为等于您的播放器对象。 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);