Applying a clicking mechanic

Hey all. I’ve been doing some editing on this script:

using UnityEngine;
using System.Collections;

public class Thing : MonoBehaviour {
	public GameObject [] doors;
	private GameObject killDoor;
	
	// Call this when init a level.
	void Start()
	{
		killDoor = doors [ Random.Range ( 4, doors.Length ) ];
	}
	
	// When player choose the door, pass the parameter here.
	void OnMouseDown ( GameObject choosenDoor )
	{
		if ( choosenDoor == killDoor )
		{
			print ( "Game over" );
			Application.LoadLevel (1);
		}
		else
		{
			print ( "Success!" );
		}
	}
}

In my game, the player has a choice on which of the 4 doors he will enter. One door, chosen at random, will kill him. The other three proceed in the game. I’m still working on doing this however, I encountered a problem. I don’t know how to make it so that the player can click the doors. I was thinking of adding void OnMouseDown but I don’t know where to put this in. Any help please?

What you want to do is attach a script similar to the one you posted to each door object in your game, and then have another script, say DoorManager, that determines which of the 4 doors will be the killer door. You would attach this DoorManager to an empty game object in your game. Is this enough or do you need more detail?

This is the script you’d attach to each door object in your game:

using UnityEngine;
using System.Collections;
 
public class Door: MonoBehaviour {
    public bool killDoor = false;
 
    // When player choose the door, pass the parameter here.
    void OnMouseDown ()
    {
        if ( killDoor )
        {
            print ( "Game over" );
            Application.LoadLevel (1);
        }
        else
            print ( "Success!" );
    }
}

This is the script you’d attach to the empty game object:

using UnityEngine;
using System.Collections;
 
public class DoorManager: MonoBehaviour {

  public GameObject [] doors;

  void Start()
    {
        doors = FindGameObjectsWithTag( "door" );
        killerDoor = doors [ Random.Range ( 0, doors.Length ) ];
        killerDoor.GetComponent<Door>().killDoor = true;
    }
}