You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity实例化管道在层级面板可见但场景中不可见问题求助

问题描述

我尝试通过预制件实例化管道,预期新管道会从首个管道的初始位置生成并向左移动,但它们在场景中不可见。这些克隆体已在层级面板中生成,但双击查看时发现其位置与首个管道重叠,我推测是新克隆体生成在同一位置导致重叠,恳请帮忙解决。

生成管道的脚本(MakePipe)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MakePipe : MonoBehaviour
{

    public GameObject pipe;
    float timer = 0;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > 1)
        {
            Instantiate(pipe);
            timer = 0;
        }
    }
}

补充说明

感谢您的回复。抱歉之前未附上负责移动的Move脚本,以下是实现管道向左匀速移动的脚本(该脚本运行正常)。但在最初的MakePipe脚本中,我仅通过Instantiate持续生成管道,是否需要在Start()方法中设置初始生成位置?

管道移动脚本(Move)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{

    public float speed;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.position += Vector3.left * speed * Time.deltaTime;
        // Debug.Log(transform.position);
    }
}

由于编辑权限限制(需10以上声望),我不得不删除相关图片:(

内容的提问来源于stack exchange,提问作者J Jung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 04:18:13