- Home /
make an object slowly appear
Hello! i would like to make an object slowly appear at a certain time. I tried to animate its alpha value but it doesn't work. There aren't any errors but in the game the object is always visible, from the starting (i've set the starting opacity value at 0). My code is something like this:
var opacity float;
function Start () {
opacity = 0;
}
function Update () {
if (Time.time > 3) {
renderer.material.color.a = opacity;
opacity += 0.2*Time.deltaTime;
}
}
Where am i wrong?
Comment
Answer by Musabbir · Jul 27, 2018 at 05:48 AM
float appearing_speed = 2f;
void Start()
{
transform.localScale = new Vector3(0,0,0);
}
void Update () {
if(Time.time > 3){
transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(1f, 1f, 1f),
appearing_speed * Time.deltaTime);
}
}
Answer by Random username · Oct 19, 2012 at 05:05 PM
I don't think you can edit the alpha component directly. Perhaps try something like this:
var opacity float;
var c Color;
function Start () {
opacity = 0;
c = renderer.material.color;
}
function Update () {
if (Time.time > 3) {
c = new Color(c.r, c.g, r.b, opacity);
opacity += 0.2*Time.deltaTime;
}
}
Your answer
Follow this Question
Related Questions
buttons opacity (or alpha) 1 Answer
How to make this image semi-transparent? 3 Answers
Opaque particles do not contain transparency 1 Answer
touch appear let go dissapear? 2 Answers