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
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));
}
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));
}