How to enable a script in Play-Mode?

Hey there.

First of all I’m quite a noob, so please be patient with me…

I’m currrently working on a jump game quite similiar to Doodle Jump.

My problem is that I want to enable a specific script as soon as the game character passes the same line as where a platform is located. So it doesn’t have tobe the case that the player gets in touch with the platform.
I tried to get and compare the position coordinates of the two objects and then wanted to check if they are equal and if this was the case, the script should be enabled.
I’ve spent lots of time with it already, but I still don’t have a solution for this.

So please please help me!

Here is the code that should enable the other script:

using UnityEngine;
using System.Collections;

public class enableScript : MonoBehaviour {
	private Transform othertransform;
	private Transform player;

	void Awake() { 
		float othertransform = GameObject.FindWithTag("MainCamera").transform.position; 
		float player = GameObject.FindWithTag ("Player").transform.position; 
	}

	void Update () {
		if (othertransform ==  player) {
		(gameObject.GetComponent( "DestroyPlatform" ) as MonoBehaviour).enabled = true;
		}
	}

}

Then this is the code that should be enabled:

#pragma strict

var othertransform : Transform;

function Awake() { 
	othertransform = GameObject.FindWithTag("MainCamera").transform; 

}

function Update () {
	if (Vector3.Distance(transform.position, othertransform.position) > 20) { 
		Destroy(this.gameObject, 5);
		
	} 
}

and finally this is what the interface of the game looks like (the camera follows the player just on y-axis btw):

52764-sample1.jpg

Thank you a lot for your help in advance!

instead of “enabling” the script, you should just write the code you need into a function, then call that function when the player touches the area. what you can do for that is put a large invisible object in that area, make sure the colllider is on and isTrigger is checked, then in a script on that object, you can use OnTriggerEnter() to call that above mentioned function. make sense?

Edit: in your case actually what you should do is have a boolean variable set to false, then it gets set to true in the OnTriggerEnter function. Then have an if statement in the update function so that it wont execute that code unless the boolean variable is true.