- Home /
Joystick Raycast Problem?
Hi to all)) I use if(Physics.Raycast(ray, out hit, 4.0f)){ for placing or delete block on screen position touch. But even if i touch my Joystick or another button, raycast delete block when i touch my Joystick. I allready try to use LayerMask but with no succes How can i ignore my Joystick from RayCasting? Can any one help me with this? Here the part of my code:
if (Input.GetMouseButtonDown(0)){
if(buttonTimer == 0){
if(hand.gameObject.active == true){
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 4.0f)){
Vector3 hitPoint = hit.point + (ray.direction.normalized * 0.01f);
IntVect blockHitPoint = new IntVect((int)hitPoint.x, (int)hitPoint.z, (int)hitPoint.y);
m_World.Dig(blockHitPoint, hitPoint);
}
buttonTimer = buttonCoolDown;
}
}
Please some one help me figure it out. I search this forum, and find some answer, but it didnt help me(
I update code to use Touch Input, but problem is still.
if (Input.touchCount == 1 ) {
Touch touch = Input.touches[0];
if(hand.gameObject.active == true){
if(touch.phase == TouchPhase.Began){
if(buttonTimer == 0){
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 4.0f)){
Vector3 hitPoint = hit.point + (ray.direction.normalized * 0.01f);
IntVect blockHitPoint = new IntVect((int)hitPoint.x, (int)hitPoint.z, (int)hitPoint.y);
m_World.Dig(blockHitPoint, hitPoint);
}
buttonTimer = buttonCoolDown;
}
}
}
}
Answer by HeadHunter2009 · Jan 12, 2012 at 02:21 AM
I made it by miself) Here Solution:
if (leftJoy.HitTest( Input.mousePosition )) {
return;
}
Answer by HeadHunter2009 · Jan 12, 2012 at 02:21 AM
I made it by miself)) Here solution: if (leftJoy.HitTest( Input.mousePosition )) {
return;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
iPhone touch raycasting 1 Answer
Casting a ray to detect the touched object in world space does not work 3 Answers
unity touch is not working properly 1 Answer
throw an object by swiping on it 0 Answers