How to Activate Script in another Object?

Pretty simple, hopefully, but I’m a complete disaster with scripting. I’m using a Lerp script that moves an object from Point A to Point B which is great. However, I’d like to enable that movement, via another script, only when another object has been clicked. I’ve attempted various solutions with no luck.

Here’s the movement script (called Lerp2)

// Transforms to act as start and end markers for the journey.
	var startMarker: Transform;
	var endMarker: Transform;

// Movement speed in units/sec.
	var speed = 1.0;
	// Time when the movement started.
	private var startTime: float;
	// Total distance between the markers.
	private var journeyLength: float;
	var target : Transform;
	var smooth = 5.0;
	function Start() {
		// Keep a note of the time the movement started.
		startTime = Time.time;
		// Calculate the journey length.
		journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
	// Follows the target position like with a spring
	function Update () {
// Distance moved = time * speed.
		var distCovered = (Time.time - startTime) * speed;
		// Fraction of journey completed = current distance divided by total distance.
		var fracJourney = distCovered / journeyLength;
		// Set our position as a fraction of the distance between the markers.
		transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);

I’m assuming there’s an easy way using OnMouseOver and GetMouseButtonDown to have a line of code that activates this script from another object.

Thanks in advance :slight_smile:

to connect scripts…

(at top of file)

var scriptVar : exactNameOfScriptYouWishToAccess;

to call a function on that script from the one you included (as seen above)


Remember: You’ll have to connect the scripts in the inspector by dragging the object that contains the specified script on it.