Forum rules - please read before posting.

Custom Action FadeIn problem

edited April 2015 in Technical Q&A
 Still very much new to Unity.

 I've made FadeIn object sprite work with my OnMouseDown
and I thought I'd hook it to AC and share it with you. But having few problems, despite having completed Custom Action tutorial.

This is the FadeIn code:

using UnityEngine;
using System.Collections;

public class FadeInSprite : MonoBehaviour
{
    public float minimum = 0.0f;
    public float maximum = 1f;
    public float duration = 5.0f;
    private float startTime;
    public SpriteRenderer sprite;


    void Start() {
        startTime = Time.time;
    }
    void Update() {
        float t = (Time.time - startTime) / duration;
        sprite.color = new Color(1f,1f,1f,Mathf.SmoothStep(minimum, maximum, t)); 
    }
}
____________________________________________________

And this is Custom Action code:

using UnityEngine;
using System.Collections;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC

{
    [System.Serializable]
    public class FadeInSprite
    {
        // Declare variables here
        public GameObject objectToAffect;
        public bool FadeInState;

        public float minimum = 0.0f;
        public float maximum = 1f;
        public float duration = 5.0f;
        private float startTime;
        public SpriteRenderer sprite;

    public FadeInSprite ()
    {
        this.isDisplayed = true;
        category = ActionCategory.Custom;
        title = "Object: FadeInSprite";
        description = "This is a blank Action template.";
    }

    override public float Run ()   // Problem here Unity console says AC.FadeInSprite.Run()' is marked as an override but no suitable method found to override

    {
                    startTime = Time.time;
       }
            override public float Update()   // Problem here Unity console says AC.FadeInSprite.Run()' is marked as an override but no suitable method found to override
        {
            float t = (Time.time - startTime) / duration;
            sprite.color = new Color(1f,1f,1f,Mathf.SmoothStep(minimum, maximum, t)); 
        }
   
    #if UNITY_EDITOR

          override public void ShowGUI () // Problem here Unity console says AC.FadeInSprite.Run()' is marked as an override but no suitable method found to override
    {
        // Action-specific Inspector GUI code here
        objectToAffect = (GameObject) EditorGUILayout.ObjectField ("GameObject to affect:", objectToAffect, typeof (GameObject), true);
        FadeInState = EditorGUILayout.Toggle ("New FadeIn state:", FadeInState);
        AfterRunningOption ();
    }
    #endif

}

}

What am I doing wrong?

Comments

  • Actually, there's just such an Action already set to be included in v1.44.

    But to correct the errors, you'd need to make your class a subclass of Action:

    So change:
    public class FadeInSprite

    to:
    public class FadeInSprite : Action
  • edited April 2015
     Thanks Chris, it would be cool to have these kind of features. As well as gradual scale up and down pulse, along with fade in and fade out.
     
    But now I'm getting the only error  here:

            override public float Update()   // Problem here Unity console says AC.FadeInSprite.Update()' is marked as an override but no suitable method found to override
            {
                float t = (Time.time - startTime) / duration;
                sprite.color = new Color(1f,1f,1f,Mathf.SmoothStep(minimum, maximum, t)); 
            }
  • Put it back to it's original form - that first line should just read "void Update ()"
  • edited April 2015
     Ok, I put it back to it's original form and changed void run to void start. And getting no errors this time.

     However nothing happens to the sprite that I assigned. I believe I did it in the right way, created a hotspot than linked to a new interaction and added this new Object: FadeInSprite action in the action and assigned my sprite object as Game Object to affect . Oh and I changed the object's sprite alpha in the inspector to zero.(e.g. made it transparent)

       void start () 
           {
                        startTime = Time.time;
           }

       void Update()  
            {
                float t = (Time.time - startTime) / duration;
                sprite.color = new Color(1f,1f,1f,Mathf.SmoothStep(minimum, maximum, t)); 
            }

  • If you're looking for help with your own scripts, better to ask on the official Unity forum.  But v1.44 should be out soon, which will have an official Action that handles this too.
  • Sounds good.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.