Game Interaction (Game Objects)

Hi.
I would like to turn OFF the game obj and its scripts attached to it when onmousedown is called, and replace with a game obj that has NO scripts. for a given amount of time…(lets say 20 seconds)…Then after those 20 seconds are up, i want to change it back to the original game obj with the scripts.

Here is the script on the PLAYER:

void Update ()
{
 if(Input.GetMouseButtonDown(0)){
  if(treeThatIsClose!=null)
  {
   RaycastHit hitInfo;
    if(Physics.Raycast(transform.position,transform.forward,out hitInfo,50f)) {
    if (hitInfo.collider.gameObject == treeThatIsClose) {
     Debug.Log ("You are facing a tree, lets start chopping");
     // Also remove the reference, we dont want to cut down the tree we just cut down
     treeThatIsClose = null;
     OnMouseDown ();
     Debug.Log ("Done chopping!");   
    }
   }
   else
   {
    Debug.Log("You are still too far away/ not looking correctly towards the tree");
   }
  }
  else
  {
   Debug.Log("You are not close to any tree so you cant hit any tree");
  }
 }
}

IEnumerator OnMouseDown ()
{
 print (Time.time);
 yield return new WaitForSeconds (Random.Range (4, 10));
 print (Time.time);
}
public void AlertTreeNearby(GameObject tree)
{
 treeThatIsClose = tree;
Debug.Log("I am near a tree! I can try cutting it down");
}

Now here is the code on the RADIUS AROUND TREE. (a TRIGGER on child game obj surrounding tree to detect player)

 void Update () {  
   }
void OnTriggerEnter(Collider col)
{
if(col.tag=="Player")
{
//Getcomponent gets a script that is on the col.gameObject which is ... on the player
//col.gameobject is the player that enters the trigger
WoodCuttingScript pScript =  col.gameObject.GetComponent<WoodCuttingScript>();
pScript.AlertTreeNearby(transform.parent.gameObject);
Debug.Log("You are near a tree");
    }
}

Any help please? :smile:

Much appreciated.

anyone?

Your over thinking it… Create a base gameObject attach the script below and call this function from the OnMouseDown() event…

transform.root.gameObject.SendMessage(“SwapObjects”,20.0f, SendMessageOptions.DontRequireReceiver);

using UnityEngine;
using System.Collections;

public class ClickController : MonoBehaviour {
	public GameObject primaryObject;
	public GameObject secondaryObject;
	
	void Start(){
		primaryObject.active=false;
		secondaryObject.active=false;
	}
	
	void SwapObjects(float timeframe){
		StartCoroutine(DoSwap(timeframe));
	}
	
	private IEnumerator DoSwap(float timeframe)
	{
		primaryObject.active=!primaryObject.active;
		secondaryObject.active=!secondaryObject.active;
		print (Time.time);
		yield return new WaitForSeconds(timeframe);
		print (Time.time);
		primaryObject.active=!primaryObject.active;
		secondaryObject.active=!secondaryObject.active;
	}
}

i call swap objects right?