【问题标题】:i have a bug with my ship, it doesn't want to appear in my game side and i dont know why我的船有一个错误,它不想出现在我的游戏中,我不知道为什么
【发布时间】:2018-08-26 09:47:14
【问题描述】:

这些是我飞船的设置

这些是我的相机设置

这是添加到船的代码,我的问题如你所见,我在游戏中找不到我的船,这后来导致了很多问题:(

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);
    }
}

【问题讨论】:

  • 奇怪的问题。重启 Unity。删除PlayerControll 脚本并新建一个。

标签: c# unity3d game-development


【解决方案1】:

首先,您的PlayerControll 脚本有一些编译时错误,必须先修复这些错误才能继续。确保代码没有任何错误,正如@Programmer 提到的,只需重新启动 Unity 或重新创建脚本。

然后尝试更改您的船的 z 位置。目前你的相机和船都在z=0,这可能是你看不到你的船的原因。将它向后/向前移动一点。

【讨论】:

    猜你喜欢
    • 2023-02-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多