我已经将玩家标签给予了游戏对象仍然代码不能在团结中工作..这是一个飞扬的鸟类游戏。
public class CameraTracks : MonoBehaviour {
Transform player;
float offsetx;
// Use this for initialization
void Start () {
GameObject player_go=GameObject.FindGameObjectWithTag("Player");
if (player_go == null) {
Debug.LogError("could not find game object with tag player");
return;
}
player =player_go.transform;
offsetx = transform.position.x - player.position.x;
}
// Update is called once per frame
void Update () {
if (player != null) {
Vector3 pos=transform.position;
pos.x = player.position.x + offsetx;
transform.position=pos;
}
}
}
答案 0 :(得分:0)
您应该将此脚本附加到要跟踪播放器的摄像机,因为全局transform
指的是附加到脚本的对象的transfrom。