Highlight (seleção) não funciona corretamente no menu
3 participantes
Página 1 de 1
Highlight (seleção) não funciona corretamente no menu
Boa noite colegas, venho solicitar o auxílio de vocês para a possível solução deste contratempo. Tenho um menu no meu projeto, é um menu principal e um de pausa. O problema ocorre no de pausa, ao pausar o jogo apertando Esc e passar a seta do mouse sobre os botões eles não são selecionados e não podem ser clicados. No entanto, se eu apertar Esc novamente os botões passam a ser selecionáveis. Gostaria de saber como fazer para que os botões possam ser selecionáveis da primeira vez que apertar Esc. Não creio que o problema esteja no script, pois isso ocorreu com outros menus que testei também.
Re: Highlight (seleção) não funciona corretamente no menu
Provavelmente é problema de hierarquia, coloque o menu que aparece quando clica em Esc como prioridade, A Unity considera a ordem que os dois objetos estão na hierarquia pra definir qual vai checar o hit do toque primeiro, se detectar, ele não testa o outro.
Tente colocar o painel do menu de pausa abaixo do painel principal.
Outra coisa, se tiver usando canvas diferente pros dois, olhe o sort order do Canvas, valores mais altos tem prioridade.
Ou algo que é desativado com o Esc está ativado por padrão, na primeira vez que você ativa ele permanece bloqueando o click, na segunda vez ele é desativado e a partir dai funciona. veja se tem algum painel ou elemento da UI esquecido ativado.
Tente colocar o painel do menu de pausa abaixo do painel principal.
Outra coisa, se tiver usando canvas diferente pros dois, olhe o sort order do Canvas, valores mais altos tem prioridade.
Ou algo que é desativado com o Esc está ativado por padrão, na primeira vez que você ativa ele permanece bloqueando o click, na segunda vez ele é desativado e a partir dai funciona. veja se tem algum painel ou elemento da UI esquecido ativado.
Fagner- Moderador
- PONTOS : 4393
REPUTAÇÃO : 667
Áreas de atuação : Modelagem 3D, Programação.
Respeito as regras :
Re: Highlight (seleção) não funciona corretamente no menu
Problema solucionado. Resolvi com esses dois scripts:
[size=32]using System;[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32][RequireComponent(typeof(InteractionRayCaster))][/size]
[size=32]public class CursorController : MonoBehaviour {[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] // Update is called once per frame[/size]
[size=32] void Update () {[/size]
[size=32] //Unlock Cursor[/size]
[size=32] if (Input.GetKey(KeyCode.Escape))[/size]
[size=32] {[/size]
[size=32] Cursor.lockState = CursorLockMode.None;[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] void ChangeCursor()[/size]
[size=32] {[/size]
[size=32] throw new NotImplementedException();[/size]
[size=32] }[/size]
[size=32] void HideCursor()[/size]
[size=32] {[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] public void ChangeCursorIcon(Texture2D texture)[/size]
[size=32] {[/size]
[size=32] Cursor.SetCursor(texture, Vector2.zero, CursorMode.ForceSoftware);[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32]public class InteractionRayCaster : CameraRaycaster {[/size]
[size=32] public delegate void TargetChanged();[/size]
[size=32] public event TargetChanged onTargetChange;[/size]
[size=32] public delegate void NoTarget();[/size]
[size=32] public event NoTarget onNoTarget;[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] [/size]
[size=32] [/size][size=32]// Update is called once per frame[/size]
[size=32] [/size][size=32]void Update () {[/size]
[size=32] // normal every frame cast for object interaction[/size]
[size=32] if (ShootRay())[/size]
[size=32] {[/size]
[size=32] // for entering check weather ray hits another object, so to reduce calls.[/size]
[size=32] if (prevHit.point != currentHit.point)[/size]
[size=32] {[/size]
[size=32] onTargetChange();[/size]
[size=32] }[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] else[/size]
[size=32] {[/size]
[size=32] if(onNoTarget != null) onNoTarget();[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] // we want a nullable return type[/size]
[size=32] public override bool ShootRay()[/size]
[size=32] {[/size]
[size=32] // the viewport vector is in (x,y) with 0 being bottom and 1 top of the viewport.[/size]
[size=32] camAim = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));[/size]
[size=32] if (Physics.Raycast(camAim,cam.transform.forward ,out currentHit, rayRange))[/size]
[size=32] {[/size]
[size=32] return true;[/size]
[size=32] }[/size]
[size=32] return false;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System;[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32][RequireComponent(typeof(InteractionRayCaster))][/size]
[size=32]public class CursorController : MonoBehaviour {[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] // Update is called once per frame[/size]
[size=32] void Update () {[/size]
[size=32] //Unlock Cursor[/size]
[size=32] if (Input.GetKey(KeyCode.Escape))[/size]
[size=32] {[/size]
[size=32] Cursor.lockState = CursorLockMode.None;[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] void ChangeCursor()[/size]
[size=32] {[/size]
[size=32] throw new NotImplementedException();[/size]
[size=32] }[/size]
[size=32] void HideCursor()[/size]
[size=32] {[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] public void ChangeCursorIcon(Texture2D texture)[/size]
[size=32] {[/size]
[size=32] Cursor.SetCursor(texture, Vector2.zero, CursorMode.ForceSoftware);[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32]public class InteractionRayCaster : CameraRaycaster {[/size]
[size=32] public delegate void TargetChanged();[/size]
[size=32] public event TargetChanged onTargetChange;[/size]
[size=32] public delegate void NoTarget();[/size]
[size=32] public event NoTarget onNoTarget;[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] [/size]
[size=32] [/size][size=32]// Update is called once per frame[/size]
[size=32] [/size][size=32]void Update () {[/size]
[size=32] // normal every frame cast for object interaction[/size]
[size=32] if (ShootRay())[/size]
[size=32] {[/size]
[size=32] // for entering check weather ray hits another object, so to reduce calls.[/size]
[size=32] if (prevHit.point != currentHit.point)[/size]
[size=32] {[/size]
[size=32] onTargetChange();[/size]
[size=32] }[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] else[/size]
[size=32] {[/size]
[size=32] if(onNoTarget != null) onNoTarget();[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] // we want a nullable return type[/size]
[size=32] public override bool ShootRay()[/size]
[size=32] {[/size]
[size=32] // the viewport vector is in (x,y) with 0 being bottom and 1 top of the viewport.[/size]
[size=32] camAim = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));[/size]
[size=32] if (Physics.Raycast(camAim,cam.transform.forward ,out currentHit, rayRange))[/size]
[size=32] {[/size]
[size=32] return true;[/size]
[size=32] }[/size]
[size=32] return false;[/size]
[size=32] }[/size]
[size=32]}[/size]
Re: Highlight (seleção) não funciona corretamente no menu
[size=32]using System;[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32][RequireComponent(typeof(InteractionRayCaster))][/size]
[size=32]public class CursorController : MonoBehaviour {[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] // Update is called once per frame[/size]
[size=32] void Update () {[/size]
[size=32] //Unlock Cursor[/size]
[size=32] if (Input.GetKey(KeyCode.Escape))[/size]
[size=32] {[/size]
[size=32] Cursor.lockState = CursorLockMode.None;[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] void ChangeCursor()[/size]
[size=32] {[/size]
[size=32] throw new NotImplementedException();[/size]
[size=32] }[/size]
[size=32] void HideCursor()[/size]
[size=32] {[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] public void ChangeCursorIcon(Texture2D texture)[/size]
[size=32] {[/size]
[size=32] Cursor.SetCursor(texture, Vector2.zero, CursorMode.ForceSoftware);[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32]public class InteractionRayCaster : CameraRaycaster {[/size]
[size=32] public delegate void TargetChanged();[/size]
[size=32] public event TargetChanged onTargetChange;[/size]
[size=32] public delegate void NoTarget();[/size]
[size=32] public event NoTarget onNoTarget;[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] [/size]
[size=32] [/size][size=32]// Update is called once per frame[/size]
[size=32] [/size][size=32]void Update () {[/size]
[size=32] // normal every frame cast for object interaction[/size]
[size=32] if (ShootRay())[/size]
[size=32] {[/size]
[size=32] // for entering check weather ray hits another object, so to reduce calls.[/size]
[size=32] if (prevHit.point != currentHit.point)[/size]
[size=32] {[/size]
[size=32] onTargetChange();[/size]
[size=32] }[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] else[/size]
[size=32] {[/size]
[size=32] if(onNoTarget != null) onNoTarget();[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] // we want a nullable return type[/size]
[size=32] public override bool ShootRay()[/size]
[size=32] {[/size]
[size=32] // the viewport vector is in (x,y) with 0 being bottom and 1 top of the viewport.[/size]
[size=32] camAim = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));[/size]
[size=32] if (Physics.Raycast(camAim,cam.transform.forward ,out currentHit, rayRange))[/size]
[size=32] {[/size]
[size=32] return true;[/size]
[size=32] }[/size]
[size=32] return false;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32][RequireComponent(typeof(InteractionRayCaster))][/size]
[size=32]public class CursorController : MonoBehaviour {[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] // Update is called once per frame[/size]
[size=32] void Update () {[/size]
[size=32] //Unlock Cursor[/size]
[size=32] if (Input.GetKey(KeyCode.Escape))[/size]
[size=32] {[/size]
[size=32] Cursor.lockState = CursorLockMode.None;[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] void ChangeCursor()[/size]
[size=32] {[/size]
[size=32] throw new NotImplementedException();[/size]
[size=32] }[/size]
[size=32] void HideCursor()[/size]
[size=32] {[/size]
[size=32] Cursor.visible = false;[/size]
[size=32] }[/size]
[size=32] public void ChangeCursorIcon(Texture2D texture)[/size]
[size=32] {[/size]
[size=32] Cursor.SetCursor(texture, Vector2.zero, CursorMode.ForceSoftware);[/size]
[size=32] Cursor.visible = true;[/size]
[size=32] Cursor.lockState = CursorLockMode.Locked;[/size]
[size=32] }[/size]
[size=32]}[/size]
[size=32]using System.Collections;[/size]
[size=32]using System.Collections.Generic;[/size]
[size=32]using UnityEngine;[/size]
[size=32]public class InteractionRayCaster : CameraRaycaster {[/size]
[size=32] public delegate void TargetChanged();[/size]
[size=32] public event TargetChanged onTargetChange;[/size]
[size=32] public delegate void NoTarget();[/size]
[size=32] public event NoTarget onNoTarget;[/size]
[size=32] // Use this for initialization[/size]
[size=32] void Start () {[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] [/size]
[size=32] [/size][size=32]// Update is called once per frame[/size]
[size=32] [/size][size=32]void Update () {[/size]
[size=32] // normal every frame cast for object interaction[/size]
[size=32] if (ShootRay())[/size]
[size=32] {[/size]
[size=32] // for entering check weather ray hits another object, so to reduce calls.[/size]
[size=32] if (prevHit.point != currentHit.point)[/size]
[size=32] {[/size]
[size=32] onTargetChange();[/size]
[size=32] }[/size]
[size=32] prevHit = currentHit;[/size]
[size=32] }[/size]
[size=32] else[/size]
[size=32] {[/size]
[size=32] if(onNoTarget != null) onNoTarget();[/size]
[size=32] }[/size]
[size=32] }[/size]
[size=32] // we want a nullable return type[/size]
[size=32] public override bool ShootRay()[/size]
[size=32] {[/size]
[size=32] // the viewport vector is in (x,y) with 0 being bottom and 1 top of the viewport.[/size]
[size=32] camAim = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));[/size]
[size=32] if (Physics.Raycast(camAim,cam.transform.forward ,out currentHit, rayRange))[/size]
[size=32] {[/size]
[size=32] return true;[/size]
[size=32] }[/size]
[size=32] return false;[/size]
[size=32] }[/size]
[size=32]}[/size]
Re: Highlight (seleção) não funciona corretamente no menu
Desculpa, eu colei os scripts, mas eles ficaram bagunçados, não sei a razão.
Re: Highlight (seleção) não funciona corretamente no menu
Muito provalvelmente deve ser efeito do editor de texto que está usando, porém, há de acontecer. :D.
Espero não ter consumido nenhum caractere necessário do seu código, resolvi aqui com Vim (editor de texto para idosos).
Espero não ter consumido nenhum caractere necessário do seu código, resolvi aqui com Vim (editor de texto para idosos).
- CursorController:
- Código:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(InteractionRayCaster))]
public class CursorController : MonoBehaviour {
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update () {
//Unlock Cursor
if (Input.GetKey(KeyCode.Escape))
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
void ChangeCursor()
{
throw new NotImplementedException();
}
void HideCursor()
{
Cursor.visible = false;
}
public void ChangeCursorIcon(Texture2D texture)
{
Cursor.SetCursor(texture, Vector2.zero, CursorMode.ForceSoftware);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Locked;
}
}
- InteractionRayCaster:
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractionRayCaster : CameraRaycaster {
public delegate void TargetChanged();
public event TargetChanged onTargetChange;
public delegate void NoTarget();
public event NoTarget onNoTarget;
// Use this for initialization
void Start () {
prevHit = currentHit;
}
// Update is called once per frame
void Update () {
// normal every frame cast for object interaction
if (ShootRay())
{
// for entering check weather ray hits another object, so to reduce calls.
if (prevHit.point != currentHit.point)
{
onTargetChange();
}
prevHit = currentHit;
}
else
{
if(onNoTarget != null) onNoTarget();
}
}
// we want a nullable return type
public override bool ShootRay()
{
// the viewport vector is in (x,y) with 0 being bottom and 1 top of the viewport.
camAim = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
if (Physics.Raycast(camAim,cam.transform.forward ,out currentHit, rayRange))
{
return true;
}
return false;
}
}
classicandsimple- ProgramadorMaster
- PONTOS : 1217
REPUTAÇÃO : 26
Áreas de atuação : Desenvolvimento de software (iniciante com linguagem C).
Respeito as regras :
Tópicos semelhantes
» (DUVIDA) Pq os Graficos Não Diminuem Corretamente?
» [DÚVIDA] Modelo do Sketchup não importa corretamente
» Pause Menu: botões de "Restart" e "Menu"
» Menu Principal com Load Game e Menu de Pause com Save Game?
» Som de tiro não funciona corretamente.
» [DÚVIDA] Modelo do Sketchup não importa corretamente
» Pause Menu: botões de "Restart" e "Menu"
» Menu Principal com Load Game e Menu de Pause com Save Game?
» Som de tiro não funciona corretamente.
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos