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?
Much appreciated.