[英]i have a bug with my ship, it doesn't want to appear in my game side and i dont know why
這些是我船的設置
這些是我的相機設定
這是添加到飛船上的代碼,您所看到的我的問題是我在游戲中找不到我的飛船,后來又造成了很多問題:(
using UnityEngine;
using System.Collections;
public class PlayerControll : MonoBehaviour {
public float speed = 5.0f;
float xmin;
float xmax;
void Start(){
float distance = transform.position.z - Camera.main.transform.position.z;
Vector3 leftmost = Camera.main.ViewportToWorldPoint(new Vector3(0,0,distance));
Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1,0,distance));
xmin = leftmost.x;
xmax = rightmost.x;
}
void Update () {
if(Input.GetKey(KeyCode.LeftArrow)){
transform.position += Vector3.left * speed * Time.deltaTime;
}else if (Input.GetKey(KeyCode.RightArrow)){
transform.position += Vector3.right * speed * Time.deltaTime;
}
float newX = Mathf.Clamp (transform.position.x, xmin, xmax);
transform.position = new Vector3 (newX, transform.position.y, transform.position.z);
}
}
首先,您的PlayerControll
腳本有一些編譯時錯誤,必須先解決這些錯誤,然后才能繼續。 確保代碼沒有任何錯誤,並且正如@Programmer所述,只需重新啟動Unity或重新創建腳本即可。
然后嘗試更改船的z位置。 當前,您的相機和飛船都位於z=0
,這可能是您看不到飛船的原因。 向后/向前移動一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.