Reputation: 35
In a Unity3d application am trying to detect a click in a certain squared area of the current camera. Is there any way to do that?
Thank you
Upvotes: 2
Views: 14401
Reputation: 31
I also use this code piece to detect if the cursor in Game View.
Vector2 mPos = Mouse.current.position.ReadValue();
if (mPos.x > 0 && mPos.x < Screen.width && mPos.y > 0 && mPos.y <
Screen.height)
{
DoSomeMethods();
}
But i feel something is still not like i want. :)
Upvotes: 0
Reputation: 5800
Is this not what you're looking for?
http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html
** EDIT **
using UnityEngine;
public class example : MonoBehaviour
{
void Update()
{
// Left-half of the screen.
Rect bounds = new Rect(0, 0, Screen.width/2, Screen.height);
if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition))
{
Debug.Log("Left!");
}
}
}
Upvotes: 8