Search Unity

4.6 Button Animation with Transparent, non interactive backgroud.

Discussion in 'UGUI & TextMesh Pro' started by El Maxo, May 21, 2015.

  1. El Maxo

    El Maxo

    Joined:
    May 23, 2013
    Posts:
    177
    Hello Everyone,

    I am currently trying to make a button animate in its still state (non mouse over or clicked). I created a animation in after effects and brought it into unity where I have successfully been able to create a script (with the help of the unity answers fokes) that plays the animation, and it is interaction with mouse overs. My problem is the colliders that come with this animation, the collider picks up a square around the object and doesn't ignore the blank areas (alpha). I have come across this problem before and managed to ger rid of it with a advanced texture and script with a "eventAlphaThreshold". Al thought they way I animate my button is different and "eventAlphaThreshold" doesn't work on sprites. So I am asking how can I make the alpha/transparent part of my button non-interactive while still keeping my animation.

    Collider looks like this (square is collider, circle is button (is filled in game)) :



    Code that I have attempted is bellow, it doesn't work , this is due to sprites not working with "eventAlphaThreshold"

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class Animation : MonoBehaviour {
    5.      public Image wheretoputit;
    6.      public Sprite[] images;
    7.      int fps = 10;
    8.      // Use this for initialization
    9.      void Start () {
    10.    
    11.      }
    12.    
    13.      // Update is called once per frame
    14.      void Update () {
    15.          int index = (int)((Time.time * fps) % images.Length);
    16.          images[index].eventAlphaThreshold = 0.5f; // doesnt work ( `UnityEngine.Sprite' does not contain a definition for `eventAlphaThreshold' )
    17.          wheretoputit.sprite = images [index];
    18.      }
    19. }
     
  2. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    Shouldn't you be setting eventAlphaThreshold on the wheretoputit image instead of the sprite?
     
  3. El Maxo

    El Maxo

    Joined:
    May 23, 2013
    Posts:
    177
    cheers I will give that a go