Game Development Reference
In-Depth Information
//Awake function - called at start up
void Awake()
{
//Get collider
Col = GetComponent<Collider>();
}
//---------------------
//Start Coroutine
void Start()
{
StartCoroutine(UpdateMouse());
}
//---------------------
public IEnumerator UpdateMouse()
{
//Are we being intersected
bool bIntersected = false;
//Is button down or up
bool bButtonDown = false;
//Loop forever
while(true)
{
//Get mouse screen position in terms of X and Y
//You may need to use a different camera
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//Test ray for collision against this collider
if (Col.Raycast(ray, out hit, Mathf.Infinity))
{
//Object was interesected
if(!bIntersected) SendMessage("OnMouseEnter",
SendMessageOptions.DontRequireReceiver);
bIntersected = true;
//Test for mouse events
if(!bButtonDown && Input.GetMouseButton(0))
{
bButtonDown = true; SendMessage("OnMouseDown",
SendMessageOptions.DontRequireReceiver);
 
Search WWH ::




Custom Search