- Home /
Simple Blinking when mouse click script help
this script works, when play, the sphere will start blinking. which is not what i wanted. i wanted it to blink when i Input.GetMouseButtonDown(0). i try to put the sphere_blink(); inside Input.GetMouseButtonDown(0). But it will on when first click and off 2nd click. which also wrong. what i wanted is when i Click, then the sphere start Blinking. some1 please help me check where should i change in my script. Thx
private var hitPos : Vector3 ;
private var hitObjectPos : Vector3 ;
private var hit : RaycastHit ;
private var Down : boolean = false;
private var blip : GameObject ; //<--sphere11
var timer : double ;
var onoff : boolean;
function Start(){
blip = GameObject.Find("Sphere11") ;
blip.renderer.enabled = false ;
}
function Update(){
sphere_blink();
if(Input.GetMouseButtonDown(0)){
Down = Input.GetMouseButtonDown(0);
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition) ;
blip.renderer.enabled = true ;
if(Physics.Raycast(ray , hit)){
hitPos = hit.point ;
hitObjectPos = hit.transform.position ;
}
}
}
function FixedUpdate(){
blip.transform.position = Vector3(hitPos.x , 5 , hitPos.z) ;
}
function OnGUI(){
//The world position of the ray's contact point->
if(Down == true){
GUI.Label(Rect(5,50,200,50),hitPos+ "") ;
}
}
function sphere_blink()
{
if (Time.time > timer)
{
timer = Time.time + .4;
onoff = !onoff;
blip.renderer.enabled = onoff;
}
}
why cannot you use simple mouse down function than ray cast hit .when mouse is down inside the loop call that blinking function
dont quite understand what you mean, but didnt i explain at top when mouse is down inside the loop call that blinking function is not working, 1st down = blink show up and 2nd down blink gone 3rd show up again, So it shouldnt be like this, it should be when 1st down ,it auto keep blinking
Answer by ByteSheep · Jan 19, 2012 at 01:28 AM
This should make the sphere start blinking as soon as the mouse button is pressed, I've added a boolean to check if the Blink function whether the mouse button has been pressed:
private var hitPos : Vector3 ;
private var hitObjectPos : Vector3 ;
private var hit : RaycastHit ;
private var Down : boolean = false;
private var blip : GameObject ; //<--sphere11
var timer : double ;
var onoff : boolean;
var StartBlinking : boolean;
function Start(){
blip = GameObject.Find("Sphere11") ;
blip.renderer.enabled = false ;
StartBlinking = false;
}
function Update(){
sphere_blink();
if(Input.GetMouseButtonDown(0)){
StartBlinking = true;
Down = Input.GetMouseButtonDown(0);
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition) ;
blip.renderer.enabled = true ;
if(Physics.Raycast(ray , hit)){
hitPos = hit.point ;
hitObjectPos = hit.transform.position ;
}
}
}
function FixedUpdate(){
blip.transform.position = Vector3(hitPos.x , 5 , hitPos.z) ;
}
function OnGUI(){
//The world position of the ray's contact point->
if(Down == true){
GUI.Label(Rect(5,50,200,50),hitPos+ "") ;
}
}
function sphere_blink()
{
if (Time.time > timer && StartBlinking)
{
timer = Time.time + .4;
onoff = !onoff;
blip.renderer.enabled = onoff;
}
}
merry christmas,can you $$anonymous$$ch me how to do some kinds of boolean true or false as what LoONuhti$$anonymous$$ said on my question How to make helicopter fall and explosion
Your answer

Follow this Question
Related Questions
Paring json Array object 3 Answers
how to make a sphere/ball blinking 4 Answers
Problem with shaders and textures: drop FPS and blinks 2 Answers
Gameboard, next position on a path 2 Answers
How to store character coordinates and quest progress between scenes? 3 Answers