Basic Vector 2 question

Hi

I want to destroy the object if it hits another object or it travel 8 to on the VectorX
I have this as below but it does not work

var Speed : float;
var Position : float;

function Awake (){
Position = transform.position.x;
print(Position);
}
function Update () {

transform.Translate(Speed * Time.deltaTime,0,0);

if (Position == Position + 8 ) {
Destroy(gameObject);
}
}

function OnTriggerEnter (col : Collider ) {

Destroy(gameObject);

}

If it’s in world coordinates, transform.position.x

if ( Position == Position + 8 )

Position is not equal to Position + 8. It just isn’t.

You want
if ( transform.position.x >= position+8.0 )

Also, keeping your variables to camelCase and your functions in CamelCase will greatly help with readability in the long run. :slight_smile: