Search Unity

Changine Values in Animaiton Panel

Discussion in 'Scripting' started by realblues, Sep 4, 2012.

  1. realblues

    realblues

    Joined:
    Dec 10, 2010
    Posts:
    10
    Sometimes My 2D Sprite needs Change Somthing while Animation, so I Created DepthController.cs as Following Code:

    Code (csharp):
    1. public class DepthController : MonoBehaviour {
    2.     [SerializeField]public float mDepth;
    3.    
    4.     Sprite spr;
    5.    
    6. }
    It Shows like this:

    $ScreenShot.png

    So, My Designer can Change DepthController.mDepth well.

    But My Goal is to Call spr.SetDepth(depth) if mDepth is Changed.

    Can it be possible?
     
  2. PAEvenson

    PAEvenson

    Joined:
    Nov 12, 2009
    Posts:
    47
    The quick and dirty way would be to check, in update, if mdepth changed...

    Code (csharp):
    1.  
    2. private float m_PreviousDepthValue = 0.0f;
    3.  
    4. void Update()
    5. {
    6.     if(mDepth != m_PreviousDepthValue)
    7.     {
    8.         spr.SetDepth(mdepth);
    9.     }
    10.     m_previousDepthValue = mDepth;
    11. }
    12.