[SOLVED]My OnMuseDown execute only once
I have the following scripts:
void Start()
{
thisTurret = this.gameObject;
//InvokeRepeating("UpdateTarget", 0f, 0.5f);
buildManager = BuildManager.instance;
}
private void OnMouseDown()
{
Debug.Log("This turret is: " + thisTurret.ToString());
if (EventSystem.current.IsPointerOverGameObject())
{
return;
}
if (thisTurret != null)
{
buildManager.SelectTurret(this);
}
}
and
public void SelectTurret(Turret turret)
{
if(selectedTurret == turret)
{
//Debug.Log("Selected turret is: " + selectedTurret.ToString());
DeselectTurret(selectedTurret);
return;
}
selectedTurret = turret;
//Debug.Log("Selected turret here is: " + selectedTurret.ToString());
//Debug.Log("Pasted turret here is: " + turret.ToString());
if (oldSelectedTurret == null)
{
oldSelectedTurret = selectedTurret;
}
//Debug.Log("Selected turret is: " + selectedTurret.ToString());
if (oldSelectedTurret != selectedTurret)
{
turretUI.Hide(oldSelectedTurret);
//Debug.Log("Old in if Selected turret is: " + oldSelectedTurret.ToString());
oldSelectedTurret = selectedTurret;
}
Debug.Log("Current Selected turret is: " + selectedTurret.ToString());
turretToBuild = null;
turretUI.SetTarget(selectedTurret);
}
public void DeselectTurret(Turret turret)
{
if(turret != null)
{
//Debug.Log("Turret to deselect is: " + turret.ToString());
turretUI.Hide(turret);
selectedTurret = null;
}
else
{
//Debug.Log("Turret to deselect is null!");
}
}
As the title say the OnMouseDown() executes only once then stop working and is not the console collapse
Could it be that you are hiding the collider after the first click.
From the docs about $$anonymous$$onoBehaviour.On$$anonymous$$ouseDown():
On$$anonymous$$ouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider. This event is sent to all scripts of the Collider or GUIElement.
Answer by DaresFireson · Apr 17, 2019 at 02:27 PM
It seems I was changing Layers but not all the children layers
Your answer
Follow this Question
Related Questions
On Off sound 0 Answers
Problem with Score/Highscore script 0 Answers
Why object's doesn't stop on collision enter? 0 Answers
Unity Crashes When Clicking Play: Script Error? 1 Answer
RPG instantiate problem 3 Answers