objectmoving help

Hi my name is Dino. My game is about ball jumping and moves to right and should not tag objects. Objects are constantly moving. So what I want to do… I want my object moving only when there are inside of camera or other idea is I copy few time object moving script and put it inside object for certain instances. So when my player tag collider my object moving script start work (first script), and then when my player tag some other collider (second script) my object moving script stop work. So how I can stop and start script? I don’t have Idea how to do this. Please help. Thanks a lot

#pragmastrict

privatevarXpos : float;
privatevarYpos : float;
privatevarmax : boolean;

varVert : boolean;
varmaxAmount : float;
varstep : float;

functionStart () {
Xpos = transform.position.x;
Ypos = transform.position.y;
}
functionUpdate () {

//SETTHEMAX
if(Vert){ //Vertical
if(transform.position.y >= Ypos + maxAmount){
max = true;
}
elseif(transform.position.y <= Ypos){
max = false;
}
}
else {
if(transform.position.x >= Xpos + maxAmount){
max = true;
}
elseif(transform.position.x <= Xpos){
max=false;
}
}

//MOVINGTHEPLATFORM
if(Vert){ //Verticalmovement
if(!max){
transform.position.y += step;
}
else {
transform.position.y -= step;
}
}

else { //Horizontalmovement
if(!max){
transform.position.x += step;
}
else {
transform.position.x -= step;
}
}
}

1817286–116284–objectmoving.js (891 Bytes)

So I updated my script

varmaxAmount : float;
varstep : float;

varmovementEnabled: boolean;

movementEnabled = true;

functionchangeState(){
if(movementEnabled){
movementEnabled=false;
}
else{
movementEnabled=true;
}
}

functionStart () {
this.gameObject.tag = “movingObjects”;
Xpos = transform.position.x;
Ypos = transform.position.y;
}

functionUpdate () {
if(movementEnabled){

//SETTHEMAX
if(Vert){ //Vertical
if(transform.position.y >= Ypos + maxAmount){
max = true;
}
elseif(transform.position.y <= Ypos){
max = false;
}
}
else {
if(transform.position.x >= Xpos + maxAmount){
max = true;
}
elseif(transform.position.x <= Xpos){
max=false;
}
}

//MOVINGTHEPLATFORM
if(Vert){ //Verticalmovement
if(!max){
transform.position.y += step;
}
else {
transform.position.y -= step;
}
}

else { //Horizontalmovement
if(!max){
transform.position.x += step;
}
else {
transform.position.x -= step;
}
}
}
}

And I added tag to all my moving object tag => “movingObjects”

And now I need add script when my player tag some random collider (empty object)

functionOnTriggerEnter2D(other : Collider2D)
{
if(other.tag == “Player”)
{
enable and disable all object moving and I dont know how too do this now

Thx!
}
}

“…I want my object moving only when there are inside of camera…”

i can not java, but can you use this ?

if(renderer.isVisible)
movementEnabled=true;