- Home /
Raycast not refreshing with changing UI gameObject,pointerCurrentraycast are not updating, making unwanted error in selecting gameobject
I am making a card game. Where i have four UI for each player.
I am using Raycast for detecting gameobjects. But raycast work well for first player. As soon as i disable player 1 UI and enable second Player UI. Raycast keeps on sending details of first player.
Making difficult for me to get proper details for game.
Pic showing i have selected and thrown 2 card for player2.
pic showing i have thrown card with number 8 for player3 but raycast still shows the same number, if i pressed at same position. but if i would have selected other position. Than it would have selected player2 game objects with just below the player3 object.
Here is my input manager script
public class InputManager1 : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler { public void OnDrag(PointerEventData eventData) { CardManager1.instance.MoveCard(eventData.position); }
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject != null)
{
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<CardView>() != null)
{
CardManager1.instance.SetSelectedCard(eventData.pointerCurrentRaycast.gameObject.GetComponent<CardView>());
}
}
}
public void OnPointerUp(PointerEventData eventData)
{
CardManager1.instance.ReleaseSelectedCard();
}
Help out**
[1]: /storage/temp/168253-pic2.png
[2]: /storage/temp/168254-pic4.png
,Raycast are not updating, they are selecting gameObject which i have already disabled.
I am making a card game. Where I am using multiple UI for all four players. I have used panels for selecting gameobjects which are noting but simple images. I have given them numbers as their name so that i can easily detect them using debug.log() option.
But when I take input for first player, my raycast works well. As i disable player first ui and try to select object from second player's UI my raycast keep on selecting first gameObject.
I am confused what to do now.
I am adding the input manager script
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems;
public class InputManager1 : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler { public void OnDrag(PointerEventData eventData) { CardManager1.instance.MoveCard(eventData.position); }
public void OnPointerDown(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject != null)
{
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<CardView>() != null)
{
CardManager1.instance.SetSelectedCard(eventData.pointerCurrentRaycast.gameObject.GetComponent<CardView>());
}
}
}
public void OnPointerUp(PointerEventData eventData)
{
CardManager1.instance.ReleaseSelectedCard();
}
}
It would be very helpful if anyone can help.
Reference images: You can observe player1CardDeck gameObject is enabled but others below it are disabled. In this screenshot you can see the Console showing i have selected and thrown card with number 2.
But when i pick card from same position or any different position. Raycast show the name of player I cards. Help out if you get any clue. What to do?
Your answer
Follow this Question
Related Questions
Unity - destroy clone child object (button) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
store gameobject then manipulate with ui 1 Answer
Scroll view not scrolling when colliders are in the way 0 Answers