But it keeps throwing up loads of errors, and I’m afraid I’m not technical enough on the programming side to fix them, can anyone else get this working, or offer advice on any alternative methods
I’m using unity 4.0.1 if that means anything, the object is a standard polyplane with a .png texture on it, I’m using mobile > transparent > vertex colour and I literally just want it to fade in and out over a specified time interval.
Why not upgrade? it might help because that shader doesn’t exist or at least isn’t named that in latest version I have…
As far as the code posted in that link, there are several problems… it lists the ‘using’ items twice and there is an extra ‘}’ at the end. In any case, that code doesn’t fade the object in and out. This code fades an object in or out.
try this example code with a primitive object that has a material with a color component…and a shader like Transparency>Diffuse
using UnityEngine;
using System.Collections;
public class LerpAlpha : MonoBehaviour
{
public float duration = 1;
public float alpha = 0;
Color color;
void Start ()
{
color = renderer.material.color;
}
void Update ()
{
lerpAlpha();
}
void lerpAlpha ()
{
alpha = Mathf.PingPong(Time.time, duration) / duration;
Color tempcolor = new Color(color.r,color.g,color.b,alpha);
renderer.material.color = tempcolor;
}
}
They changed how you can get an image. You have to use OnPostRender or something like that and it has to be on the camera. I had to call a render from my main script and then pick it up and fade it in. Maybe there’s a better way, I don’t know.
Thanks all, those answers are a great help, I’ve got something working now.
I should be able to tweak for my needs, the fade in and out works as required, but ideally I’d like my object to be on screen for some time before fading, so I’m going to look at possibly randomising the fade as I’d like it to apply to a few different objects in the scene, kind of like ‘twinkling stars’ that randomly fade in and out.
The reason I’m still with 4.0.1 is a plugin I’m using for android live wallpaper development is only compatible upto this version, it doesn’t work with more recent versions of unity.