In any case, I like to code, so here it is.
A simple way you get an object to become click-able is to make sure your object has a collider and it implements one of the OnMouse methods (Like OnMouseUp, OnMouseDown). Take the following script for example:
using UnityEngine;
using System.Collections;
public class ClickableObject : MonoBehaviour
{
void OnMouseUp()
{
Debug.Log(string.Format("Object {0} was clicked.", name));
}
}
If you attach this script to an object (like a Unity sphere) and it has a collider, when that object is clicked you will see a message in your console come up.
Now we can take this functionality and add to it so that it interacts with another object. There are multiple different ways to get access to another GameObject/script, each with pros and cons, and it will be up to you to decide which one suits your needs.
One simple way to get a reference to a GameObject is to create a public member on a script of type GameObject. This will cause the Inspector (when the object with the script attached to it is selected) to give you a public property that can be modified within the editor. Now, you can take a separate GameObject from within your scene and drag it onto this new property we have created. This will give you access to that specific object you have dragged.
Let’s take the previous script and modify it so that it does what we just talked about. The script is now diamonds! I mean, the script now looks like this:
using UnityEngine;
using System.Collections;
public class ClickableObject : MonoBehaviour
{
//Here is our new inspector property. To initialize this, we drag a GameObject from our scene into the property.
public GameObject m_draggedObject;
void OnMouseUp()
{
Debug.Log(string.Format("Object {0} was clicked.", name));
//Let's make sure we actually dragged something to initiliaze this member.
if (m_draggedObject != null)
{
Debug.Log(string.Format("Name of the GameObject we are referecing is {0}.", m_draggedObject.name));
}
}
}
Provided you dragged a GameObject into the property, you will now see two debug statements in your console window. One is the original message we were previously printing, and the other is the Name of the GameObject you are now referencing.
Ok, let me know if you understand this so far and we can continue with the next part.