I need help deleting cloned objects at a axis point
I want the cloned objects to destroy when they get to -10 on the y axis
#pragma strict
var randomX=0;
var RandomX=0;
var randomRate=0;
var moveSpeed=0;
var loopy ;
var relativePositionOffset : Vector2 = Vector2(0,0);
static var clonedObject: GameObject;
loopy = GameObject.Find("floorLevel1");
function Start (){
clonedObject = Instantiate(loopy,transform.position +relativePositionOffset, Quaternion.identity);
if(transform.position.y>200){
Destroy (gameObject,1);
}
}
Invoke("RandomlyMove",randomRate);
function RandomlyMove() {
RandomX = Random.Range(2,7);
if (transform.position.x >-10&&transform.position.y>=6) {
transform.position.x =RandomX;
Comment
Please edit your question to have a sensible, informative title. And then select all your code and press the '1010101' button or ctrl+k to format the code properly! Thanks.
In Update() do something like:
Update(){
if($$anonymous$$athf.Abs(clonedObject.transform.position.y + 10) < 0.1f){
Destroy(clonedObject);
}
}
Or if you know the direction your cloned object will be moving towards -10 then you can do it more simply with the if statement:
if(clonedObject.transform.position.y > -10)
or
if(clonedObject.transform.position.y < -10)
Your answer
Follow this Question
Related Questions
Destroy object on click? UNITY 2 Answers
Why isn't my object destroying on collision? 1 Answer
Unity2D: How to destroy spawned object once it exit out of camera's view? 1 Answer
How to check if an object is passed a certain point? 0 Answers
(3d) Destroy a GameObject when player walks over it 1 Answer