C# 如何在特定时间点隐藏实例化的游戏对象?

C# 如何在特定时间点隐藏实例化的游戏对象?,c#,instantiation,mesh,unity5,gameobject,C#,Instantiation,Mesh,Unity5,Gameobject,我在游戏中实例化了四边形(带有代码);y=2时总共20个,y=2时总共20个。现在我想在某个时间点和某个时期隐藏其中一个。 我该怎么做?我的相机以0.04f的速度移动。 我已经试过了 plotBars1.GetComponent<MeshRenderer>().enabled=false; plotBars1.GetComponent().enabled=false; 然而,这隐藏了所有这些。还有我的第二个实例化对象数组(plotBars2) 下面是我的脚本代码: privat

我在游戏中实例化了四边形(带有代码);y=2时总共20个,y=2时总共20个。现在我想在某个时间点和某个时期隐藏其中一个。 我该怎么做?我的相机以0.04f的速度移动。 我已经试过了

plotBars1.GetComponent<MeshRenderer>().enabled=false; 
plotBars1.GetComponent().enabled=false;
然而,这隐藏了所有这些。还有我的第二个实例化对象数组(plotBars2)

下面是我的脚本代码:

private GameObject bar1; 
private GameObject bar2; 
private GameObject[] plotBars1;
private GameObject[] plotBars2; 
private Vector3 posBar1; 
private Vector3 posBar2; 




// Use this for initialization
void Start () {


    bar1 = GameObject.CreatePrimitive (PrimitiveType.Quad); //create a Quad
    bar1.transform.position = new Vector3 (-5, -2, 0); 

    bar2 = GameObject.CreatePrimitive (PrimitiveType.Quad); //create a Quad
    bar2.transform.position= new Vector3 (5,2,0);

    //change material to green 
    Material Material= Resources.Load ("Material/green", typeof(Material)) as Material;
    bar1.GetComponent<MeshRenderer>().material = Material; 

    //change material to green 
    bar2.GetComponent<MeshRenderer> ().material = Material;


    //change scale of quad 
    bar1.transform.localScale += new Vector3(5f,-0.5f,0);
    bar2.transform.localScale += new Vector3 (5f, -0.5f, 0); 

    float sizebar1=bar1.GetComponent<MeshRenderer> ().bounds.size.x;
    float sizebar2 = bar2.GetComponent<MeshRenderer> ().bounds.size.x; 


    plotBars1 = new GameObject[20]; //creat an array of  quads.
    plotBars2= new GameObject[20]; //create an array of quads. 


    for (int m = 1; m < 20; m += 2) {

        plotBars1 [m].GetComponent<MeshRenderer> ().enabled = false;

    }




    for (int i = 0; i < 20; i++) {

        int initalposx1 = -5;


        posBar1 = new Vector3 (initalposx1 + (i*20), -2, 0);

        plotBars1 [i] = (GameObject)GameObject.Instantiate (bar1, posBar1, Quaternion.identity);

        plotBars1 [i].active = false; 

        }




    for (int j = 0; j < 20; j++) {

        int initialposx2 = 5; 

        posBar2 = new Vector3 ( initialposx2+ (j*20), 2, 0);

        plotBars2 [j] = (GameObject)GameObject.Instantiate (bar2, posBar2, Quaternion.identity);



    }

}

// Update is called once per frame
void Update () {

}
私人游戏对象bar1;
私人游戏对象bar2;
私有游戏对象[]绘图条1;
私有游戏对象[]绘图条2;
私有向量3 posBar1;
私有向量3 posBar2;
//用于初始化
无效开始(){
bar1=GameObject.CreatePrimitive(PrimitiveType.Quad);//创建一个四元组
bar1.transform.position=新向量3(-5,-2,0);
bar2=GameObject.CreatePrimitive(PrimitiveType.Quad);//创建一个Quad
bar2.transform.position=新向量3(5,2,0);
//将材质更改为绿色
物料=资源。加载(“物料/绿色”,类型为(物料))作为物料;
bar1.GetComponent().material=物料;
//将材质更改为绿色
bar2.GetComponent().material=物料;
//更改四边形的比例
bar1.transform.localScale+=新向量3(5f,-0.5f,0);
bar2.transform.localScale+=新矢量3(5f,-0.5f,0);
float sizebar1=bar1.GetComponent().bounds.size.x;
float sizebar2=bar2.GetComponent().bounds.size.x;
plotBars1=新游戏对象[20];//创建四边形数组。
plotBars2=新游戏对象[20];//创建四边形数组。
对于(int m=1;m<20;m+=2){
plotBars1[m].GetComponent().enabled=false;
}
对于(int i=0;i<20;i++){
int initalposx1=-5;
posBar1=新向量3(initalposx1+(i*20),-2,0);
plotBars1[i]=(GameObject)GameObject.Instance(bar1,posBar1,四元数.identity);
plotBars1[i]。active=false;
}
对于(int j=0;j<20;j++){
int initialposx2=5;
posBar2=新向量3(初始值posx2+(j*20),2,0);
plotBars2[j]=(GameObject)GameObject.Instantiate(bar2,posBar2,四元数.identity);
}
}
//每帧调用一次更新
无效更新(){
}
}


谢谢你的帮助

隐藏其中一个是什么意思?隐藏一个随机的?通过阵列一次隐藏一个?隐藏意味着玩家在离开bar1时不应该看到BAR2,这样他就必须知道(根据经验)移动某个游戏对象的速度和高度。你明白我什么意思吗?