[35538-run_test.zip|35538]
==================================================
At16:25
i did something success, but someing fail
GenAndDesGround Scripts:
using UnityEngine;
using System.Collections;
public class GenAndDesGround : MonoBehaviour {
public GameObject gGameController ;
public GameController GameController ;
public GameObject gGround;
void Start () {
gGameController = GameObject.FindWithTag("GameController");
GameController = gGameController.GetComponent<GameController>();
}
void OnTriggerEnter(Collider other){
GameObject Generate = Instantiate (gGround, new Vector3 (0, 0, 18), transform.rotation) as GameObject;
Debug.Log ("Gen");
GameController.gNewGround.transform.parent = Generate.transform;
Destroy (GameController.gOldGround);
GameController.gOldGround = GameController.gNewGround;
GameController.gNewGround = Generate;
}
}
For GameController Scripts:
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public GameObject gNewGround;
public GameObject gOldGround;
// Use this for initialization
void Start () {
gOldGround = GameObject.FindGameObjectWithTag ("YellowGroundOld");
gNewGround = GameObject.FindGameObjectWithTag ("YellowGroundNew");
gOldGround.transform.parent = gNewGround.transform;
}
// Update is called once per frame
void Update () {
if(gNewGround!=null)
{
gNewGround.transform.Translate (Vector3.back*Time.deltaTime * 5);
}
}
}
Now, the problem is the generate position is keep different.
First Time generate, there are no space between OldGround and NewGround
After Trigger again and instaniate, there are space between OldGround and NewGround
After that , generate again, there are no space between OldGround and NewGround
…loop…
Can anyone help?