Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
3
Question by SaschaDeWaal · Jun 04, 2016 at 09:41 AM · uieventsystemui image

UI Clicking thought alpha of image

We have two UI images next to each other (see picture). when you click at the circle in the green area, the red area is triggert. This makes sense because the collision is a rectangle. However is it possible to let the event system ignore the parts of the image with a alpha of 1? or is there a other way to make this work?

Thanks already! alt text

uiexplane.png (165.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by adalbertomania · Oct 26, 2019 at 11:16 PM

Hi,

I came from 2019 when google is not your friend, so let me show how do this...

step1

drag the img to your project -> assets -> wherever

Configure the img: sprite 2D to unity UI create a sprite child, Alpha for transparency and Enable read/wirte for code... alt text

step2

Create a C# file and paste this code, remember to modify the class name equal your file name

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class estado_click : MonoBehaviour, IPointerDownHandler 
 {
     public Image img;
     
     void Start()
     {
         img.alphaHitTestMinimumThreshold = 0.5f;
     }
 
     public void OnPointerDown (PointerEventData eventData) 
     {
         GameObject.Find("GameObject").GetComponent<game>().estado_name( this.gameObject.name );
     }    
 
 }
 


On hierarchy add canvas-> img and set sprite the img, set RAYCAST to click trigger.

Now select in hierarchy the images (hold control if need) and add the code created

step3

click in each image :drag the sprite to source and drag the image to script parameter;

alt text

Now when click the image call "estado_name" function with the img name as parameter.

i hope it helps.


sprite-setting.png (36.6 kB)
image-setting.png (69.4 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by allenallenallen · Jun 04, 2016 at 09:49 AM

http://answers.unity3d.com/questions/821613/unity-46-is-it-possible-for-ui-buttons-to-be-non-r.html

http://answers.unity3d.com/questions/882844/how-to-stop-non-rectangular-buttons-from-overlappi.html

http://answers.unity3d.com/questions/49912/non-rectangular-buttons.html

Google is your friend.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by prasanthvel · Jun 01, 2020 at 10:46 AM

check this one https://youtu.be/79zkZRqiUxQ

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityEngine.UI and UnityEngine.EventSystem do not work, what do I do? 1 Answer

Events not working when UI y rotation is not 0 0 Answers

Using downloaded image as UI Image's source image? 1 Answer

OnPointerEnter blocked by something 2 Answers

EventSystem raycasting on World Canvas gameobject always returning worldPosition of zero 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges