Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Polygon Collider 2D affecting OnMouseEnter script

Discussion in 'Scripting' started by denholmspurr, Apr 23, 2020.

  1. denholmspurr

    denholmspurr

    Joined:
    Apr 17, 2020
    Posts:
    42
    I've encountered a tricksy problem that I've isolated the source but I'm not sure what to do about it.

    I have icons for locations in my game that when the player hovers over those icons with the mouse they get bigger and display information. That's all been working perfectly well.

    I recently added a new layer which is basically the copy of the terrain shape but as a collider for another game aspect. Now, the OnMouseEnter script isn't functioning in the areas where the collider is present. If i switch the collider off, the script works again. Any clues as to why this is happening?

    Code (CSharp):
    1.     public void OnMouseEnter()
    2.     {
    3.        
    4.  
    5.             transform.localScale += new Vector3(0.1f, 0.1f, 0f);
    6.             transform.localPosition = new Vector3(0f, 0.3f, 0f);
    7.             string objectName = gameObject.name;
    8.             cityCountryText.text = (Find_id(objectName).name);
    9.             cityText.text = (Find_id(objectName).country);
    10.             cityAreaText.text = "• Area: " + (Find_id(objectName).area); // the corresponding value in the collumn c.name on the same row as Havana
    11.             cityPopText.text = "• Population: " + cityPop;
    12.             cityDensityText.text = "• Density: " + (Find_id(objectName).density);
    13.             cityPrepText.text = "• Preparedness: " + (Find_id(objectName).prep) + "%";
    14.             totalDeathslocal.text = "• Local Deaths: " + cityTotalDeaths;
    15.        
    16.     }
     
  2. denholmspurr

    denholmspurr

    Joined:
    Apr 17, 2020
    Posts:
    42
    Is this something to do with the "Is Trigger" option? I tried deselecting it on a couple of my icons and it works-ish. Mouse Over returns but the scaling/positioning on the MouseOver goes all funky.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
  4. denholmspurr

    denholmspurr

    Joined:
    Apr 17, 2020
    Posts:
    42
    thank you, my precious! will take a looksy!
     
    Kurt-Dekker likes this.