- Home /
how to make a sphere/ball blinking
i have create a gameobject(sphere), So any1 know how to make this sphere blinking,please kindly share with me thx alot
i just need simple function like how to make the sphere keep on continue disppearing and returing. Any1 know how to do it. please kindly help me Thx
Answer by robert_mathew · Jan 17, 2012 at 10:26 AM
public GameObject ball; //assign the game object sphere or what ever you want to blink
public double timer;
public bool onoff;
void Update()
{
sphere_blink();
}
void sphere_blink()
{
if (Time.time > timer)
{
timer = Time.time + .4;
onoff = !onoff;
ball.renderer.enabled = onoff;
}//Time.time > timer ends
}//sphere_blink ends //in c# call the function sphere_blink() where ever you want the sphere to blink
var ball : GameObject ; //assign the game object sphere or what ever you want to blink
var timer : double ;
var onoff : boolean ;
function Update()
{
sphere_blink();
}
function sphere_blink()
{
if (Time.time > timer)
{
timer = Time.time + .4;
onoff = !onoff;
ball.renderer.enabled = onoff;
}//Time.time > timer ends
}//sphere_blink ends //in java script call the function sphere_blink() where ever you want the sphere to blink
This isn't really blinking. But more like, disappearing and returning...
i think by blinking he mean to on off the renderer in a particular time
This script will be attach to the sphere itself, simply want it to keep on disappearing and returing. But some how your script is not working, nothings happen, can you check it out thx
i have edited the script attach the script to the sphere you want it to appear and disappear and var ball : GameObject assign the sphere to var ball to the script which you want to make appear and disappear it will work i have tested the script it is working
Answer by ByteSheep · Jan 18, 2012 at 03:53 AM
This should work fine, as it is now it will change the color of the sphere every half second but you can adjust this by setting WaitTime to a different number :)
var timer : float;
var WaitTime : float = 0.5;
var ResetPoint : float;
function Start () {
ResetPoint = WaitTime * 2;
}
function Update () {
timer += Time.deltaTime;
if(timer < WaitTime)
{
renderer.material.color = Color.white;
}
if(timer > WaitTime)
{
renderer.material.color = Color.red;
}
if(timer > ResetPoint)
{
timer = 0;
}
}
your script works. Its for Render.color. Below is now a fine script where is blink for whole gameObjects. Nicer Thx anyway
hi merry_chirstmas i need help in you in audio sound, if you know about it, please take a look on my question (my second audio not working. Thx
Answer by Marnix · Jan 17, 2012 at 10:29 AM
You have to access the Renderer
component of your ball and change the color of the ball. Depending on what you want, you can change different kinds of colors.
There is the diffuse color (main color), which is the color that reacts on lights.
There is the ambient color, which is the color that doesn't react at all, but simply lights the object.
And sometimes, there is the specular color, which is the highlight on your object.
In a script, you could make a timer. Whenever the timer goes off, change the color. Then reset the timer and let it count again.
You will need the following components:
http://unity3d.com/support/documentation/ScriptReference/Renderer.html
http://unity3d.com/support/documentation/ScriptReference/Renderer-material.html
http://unity3d.com/support/documentation/ScriptReference/Time.html
Use this.renderer.material.color = Color.red
. Or something similar.
$$anonymous$$arnix renderer.material.color = Color.red are able to display red. So how am i going to make it auto keep on disappearing and returing, any idea i have somethings see if it is useful but i just dunno how to add it on gameobject.a = $$anonymous$$athf.Sin(Time.time * 8.0);
Answer by gingerben93 · Oct 07, 2017 at 02:25 PM
A simple way without changing current sprite colors and giving object sprite a fade in and out look would be:
PlayerSprite.color = new Color(PlayerSprite.color.r, PlayerSprite.color.b, PlayerSprite.color.g, (PlayerSprite.color.a + .05f) % 1);
Your answer
![](https://koobas.hobune.stream/wayback/20220613063104im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
indestructible gameobject 0 Answers
How can I blink a gameobject faster and faster? 1 Answer
Trying to make a renderer blink on and off, it's not working but I get no errors when building? 1 Answer
GUI text blinking opacity 1 Answer
Why are my 2D sprite GameObjects blinking and how do I fix this problem? 0 Answers