C# 雪碧没有';告诉它移动后,它就不会出现了

C# 雪碧没有';告诉它移动后,它就不会出现了,c#,unity3d,C#,Unity3d,在我最近的代码更新中,在我可以将预置拉入层次结构之前,精灵不想再显示了,它会显示出来,而且它仍然会这样做。但每当我用代码生成它时,图像就不会显示。我所做的更新产生了精灵,然后将它们移动到一条路径上。我可以在inspector中看到精灵移动,但在屏幕上看不到它 移动敌方脚本 public class MoveEnemy : MonoBehaviour { [HideInInspector] public GameObject[] waypoints; private in

在我最近的代码更新中,在我可以将预置拉入层次结构之前,精灵不想再显示了,它会显示出来,而且它仍然会这样做。但每当我用代码生成它时,图像就不会显示。我所做的更新产生了精灵,然后将它们移动到一条路径上。我可以在inspector中看到精灵移动,但在屏幕上看不到它

移动敌方脚本

public class MoveEnemy : MonoBehaviour
{

    [HideInInspector]
    public GameObject[] waypoints;
    private int currentWaypoint = 0;
    private float lastWaypointSwitchTime;
    public float speed = 1.0f;

    // Start is called before the first frame update
    void Start()
    {
        lastWaypointSwitchTime = Time.time;
    }

    // Update is called once per frame
    void Update()
    {
        // 1
        Vector3 startPosition = waypoints
        [currentWaypoint].transform.position;
        Vector3 endPosition = waypoints[currentWaypoint + 1].transform.position;

        // 2
        float pathLength = Vector3.Distance(startPosition, endPosition);
        float totalTimeForPath = pathLength / speed;
        float currentTimeOnPath = Time.time - lastWaypointSwitchTime;
        gameObject.transform.position = Vector2.Lerp(startPosition, endPosition, currentTimeOnPath / totalTimeForPath);

        // 3
        if (gameObject.transform.position.Equals(endPosition))
        {
            if (currentWaypoint < waypoints.Length - 2)
            {
                // 3.a
                currentWaypoint++;
                lastWaypointSwitchTime = Time.time;
                // TODO: Rotate into move direction
            }
            else
            {
                // 3.b
                Destroy(gameObject);

                AudioSource audioSource = gameObject.GetComponent<AudioSource>();
                AudioSource.PlayClipAtPoint(audioSource.clip, transform.position);
                // TODO: deduct health
            }
        }
    }
}

// Credit raywenderlich.com
public class SpawnEnemy : MonoBehaviour
{

    public GameObject[] waypoints;
    public GameObject testEnemyPrefab;

    // Start is called before the first frame update
    void Start()
    {
        Instantiate(testEnemyPrefab).GetComponent<MoveEnemy>().waypoints = waypoints;
    }
公共类:单一行为
{
[hideininstecpt]
公共游戏对象[]航路点;
专用int currentWaypoint=0;
私人浮动lastWaypointSwitchTime;
公共浮子速度=1.0f;
//在第一帧更新之前调用Start
void Start()
{
lastWaypointSwitchTime=Time.Time;
}
//每帧调用一次更新
无效更新()
{
// 1
矢量3起始位置=航路点
[currentWaypoint].transform.position;
Vector3 endPosition=航路点[currentWaypoint+1].transform.position;
// 2
浮点路径长度=矢量3.距离(起始位置、结束位置);
float totalTimeForPath=路径长度/速度;
float currentTimeOnPath=Time.Time-lastWaypointSwitchTime;
gameObject.transform.position=Vector2.Lerp(起始位置、结束位置、currentTimeOnPath/TotalTimeorPath);
// 3
if(gameObject.transform.position.Equals(endPosition))
{
if(当前航路点<航路点长度-2)
{
//3.a
currentWaypoint++;
lastWaypointSwitchTime=Time.Time;
//TODO:旋转到移动方向
}
其他的
{
//3.b
摧毁(游戏对象);
AudioSource AudioSource=gameObject.GetComponent();
AudioSource.PlayClipAtPoint(AudioSource.clip,transform.position);
//TODO:扣除健康费用
}
}
}
}
//瑞文德利信贷网
生成敌方脚本

public class MoveEnemy : MonoBehaviour
{

    [HideInInspector]
    public GameObject[] waypoints;
    private int currentWaypoint = 0;
    private float lastWaypointSwitchTime;
    public float speed = 1.0f;

    // Start is called before the first frame update
    void Start()
    {
        lastWaypointSwitchTime = Time.time;
    }

    // Update is called once per frame
    void Update()
    {
        // 1
        Vector3 startPosition = waypoints
        [currentWaypoint].transform.position;
        Vector3 endPosition = waypoints[currentWaypoint + 1].transform.position;

        // 2
        float pathLength = Vector3.Distance(startPosition, endPosition);
        float totalTimeForPath = pathLength / speed;
        float currentTimeOnPath = Time.time - lastWaypointSwitchTime;
        gameObject.transform.position = Vector2.Lerp(startPosition, endPosition, currentTimeOnPath / totalTimeForPath);

        // 3
        if (gameObject.transform.position.Equals(endPosition))
        {
            if (currentWaypoint < waypoints.Length - 2)
            {
                // 3.a
                currentWaypoint++;
                lastWaypointSwitchTime = Time.time;
                // TODO: Rotate into move direction
            }
            else
            {
                // 3.b
                Destroy(gameObject);

                AudioSource audioSource = gameObject.GetComponent<AudioSource>();
                AudioSource.PlayClipAtPoint(audioSource.clip, transform.position);
                // TODO: deduct health
            }
        }
    }
}

// Credit raywenderlich.com
public class SpawnEnemy : MonoBehaviour
{

    public GameObject[] waypoints;
    public GameObject testEnemyPrefab;

    // Start is called before the first frame update
    void Start()
    {
        Instantiate(testEnemyPrefab).GetComponent<MoveEnemy>().waypoints = waypoints;
    }
公共类:单一行为
{
公共游戏对象[]航路点;
公共游戏对象测试程序;
//在第一帧更新之前调用Start
void Start()
{
实例化(testEnemyPrefab).GetComponent().waypoints=waypoints;
}

我认为对象在摄影机后面生成。将摄影机向后移动一点。将视图设置为3d世界空间。然后沿z轴移动摄影机。或者更改生成点的z轴。

每当我更改摄影机渲染模式时,屏幕空间会移动,但精灵没有移动,所以我只能将其移回屏幕空间。

不是这样的在我更改画布渲染模式之前,精灵出现在完全错误的位置。不过,谢谢,这可能会在以后派上用场。如果这是您问题的正确答案,那么您应该澄清一下,并将其标记为答案,以便更多人能从您的解决方案中受益!