- Home /
Endless 3D plane repetition animated by script is not moving
Hey Everybody,
I am new to Unity and to C#. I am trying to move a plane via script. At the moment the plane is out of the camera view it should be deleted and a clone should pop up and so on. But nothing is really happening(depart from the fact that three clones pop up in my Hierarchy). Also I don't have any Compiler Errors. A mate of mine gave me the script written in Java(that worked perfectly) and I tried to translate it into C#. So there might be the Problem. Anyway I suppose something is wrong with this line:
newForest = Instantiate(child, new Vector3(transform.position.x+40,0,0),Quaternion.identity) as GameObject;
And here is the full code:
using UnityEngine;
using System.Collections;
public class ForestScript : MonoBehaviour {
public Masterscript masterParent;
public bool hasChild;
public GameObject child;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (masterParent.bodenPlatteDown)
{
transform.position = new Vector3(transform.position.x, 7 * Time.deltaTime);
}
if (transform.position.x < -100)
{
Destroy(gameObject);
}
if (!hasChild && transform.position.x < 80)
{
GameObject newForest;
ForestScript birthHelp;
newForest = Instantiate(child, new Vector3(transform.position.x+40,0,0),Quaternion.identity) as GameObject;
newForest.name = "Wald";
birthHelp = newForest.GetComponent("ForestScript") as ForestScript;
birthHelp.masterParent = masterParent;
hasChild = true;
}
}
}
The script should be activated by another one(Masterscript). I searched for two days now and tried to fix the problem with existing threads but nothing really namable changes. So I hope someone might have an idea. Thanks :-)