stop time by another script

I have a script that counts eggs as I collect them and when I get 10 and get to the wagon tag colliion item it loads the next level but I also have a timer and when I get to the wagon and have the correct amount of eggs I want it to also stop my timer. But im not sure how to make the collecion script stop the timer script.

This is my collection script: EggPickup.js

var eggDisplay : GUIText;
var egg = 0;
var eggsToWin = 20;

function Start() {
    DisplayAmount();
}

function DisplayAmount () {
    eggDisplay.text = ""+ egg + " eggs";
}

function OnTriggerEnter(other : Collider){
    if (other.CompareTag("egg")){
        egg++;
        DisplayAmount();
        Destroy(other.gameObject);
    }
    //Here we do the check to see if the player hit the trigger of the Wagon:
    if(other.CompareTag("Wagon")){ // Or whatever the tag might be.
        if(egg == eggsToWin){
            Application.LoadLevel("LevelToLoad");
        }
    }
}

And this is my Timer script: ClockScript.js

var isPaused : boolean = false;
var startTime : float; //(in seconds)
var timeRemaining : float; //(in seconds)
var outOfTime : boolean = false;

//clocktextures
var clockFGMaxWidth:float; // the starting width of the foregroundbar

var rightSide:Texture2D;
var leftSide:Texture2D;
var back:Texture2D;
var blocker:Texture2D;
var shiny:Texture2D;
var finished:Texture2D;

function Awake() 
{    
    ResetTime();
}


function Update() {

 if(Input.GetButtonDown("Pause")){
  if(!isPaused){
   Time.timeScale = 0;
   isPaused=true;
  }else{
   Time.timeScale = 1;
   isPaused=false;
   }
  }

  if (!isPaused)
  {
    // make sure the timer is not paused
    DoCountdown();
   }    
}

function DoCountdown()
{
    timeRemaining -= Time.deltaTime;
    percent = timeRemaining/startTime * 100;
	
	if (timeRemaining < 0)
	{
	   timeRemaining = 0;
	   Time.timeScale = 0;
	   isPaused = true;
	   TimeIsUp();
	}
	else
		Time.timeScale = 1;
	
	ShowTime();
}

function PauseClock()
{
   isPaused = true;
}

function UnpauseClock()
{
   isPaused = false;
}

function ShowTime() {
	var minutes : int;
	var seconds : int;
	var timeStr : String;
	minutes = timeRemaining/60;
	seconds = timeRemaining % 60;
	timeStr = minutes.ToString() + ":";
	timeStr += seconds.ToString("D2");
	guiText.text = timeStr; //display the time to the GUI
	
}

function TimeIsUp()
{
}

//Script for Pie style clock

function OnGUI ()
{
	//posoition the clock
	var pieClockX:int = 125;
	var pieClockY:int = 50;
	
	var pieClockW:int = 128; // clock width
	var pieClockH:int = 128; // clock height
	
	var pieClockHalfW:int = pieClockW * 0.5; // half the clock width
	var pieClockHalfH:int = pieClockH * 0.5; // half the clockheight

    var percent = timeRemaining/startTime * 100;
	var isPastHalfway:boolean = percent < 50;
	var clockRect:Rect = Rect(pieClockX, pieClockY, pieClockW, pieClockH);
	var rot:float = (percent/100) * 360;
	var centerPoint:Vector2 = Vector2(pieClockX + pieClockHalfW, pieClockY + pieClockHalfH);
	var startMatrix:Matrix4x4 = GUI.matrix;
	
	
	GUI.DrawTexture(clockRect, back, ScaleMode.StretchToFill, true,0);
		if(isPastHalfway)
		{
			GUIUtility.RotateAroundPivot(-rot-180, centerPoint);
			GUI.DrawTexture(clockRect, leftSide, ScaleMode.StretchToFill, true, 0);
			GUI.matrix = startMatrix;
			GUI.DrawTexture(clockRect, blocker, ScaleMode.StretchToFill, true, 0);
		}
		else
		{
			GUIUtility.RotateAroundPivot(-rot, centerPoint);
			GUI.DrawTexture(clockRect, rightSide, ScaleMode.StretchToFill, true, 0);
			GUI.matrix = startMatrix;
			GUI.DrawTexture(clockRect, leftSide, ScaleMode.StretchToFill, true, 0);
		}
	
	GUI.DrawTexture(clockRect, shiny, ScaleMode.StretchToFill, true,0);
	    if(percent <= 0)
		{	
		    GUI.DrawTexture(clockRect, finished, ScaleMode.StretchToFill,true, 0);
		    outOfTime = true;
	    	
	    	//Reset the Level
	    	if ( GUI.Button ( Rect (Screen.width / 2, Screen.height / 2, 300, 90 ), "Out of Time! Click to Restart" )) {
	        	ResetTime();
	            Application.LoadLevel("EGG");
	            
		}
	GUI.DrawTexture(clockRect, shiny, ScaleMode.StretchToFill, true, 0);

}
	   if ( outOfTime == false){
	   if ( isPaused ) {
	   if ( GUI.Button ( Rect (Screen.width / 2, Screen.height / 1.5, 300, 90 ), "Resume" )) {
	     Time.timeScale = 1.0f;
	     isPaused = false;
	     S = "Playing!";   
	    }
	  }   
	}
  }

function ResetTime() {
   
   timeRemaining = startTime;
   percent = timeRemaining/startTime * 100;
  
   
	
}

1 Answer

1

Pasting all your code that way is the best way to not receive an answer. Try to narrow it the what’s absolutely relevant next time, please.

As for the answer, I didn’t read the code but you can access a script from outside with a reference on the component (thatGameObject.GetComponent …) or by sending a message to call a function (thatGameObject.SendMessage(“StopTheTime”)).