Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by wenhua · Jan 18, 2012 at 09:30 AM · coordinatesblinking

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;



   }

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robert_mathew · Jan 18, 2012 at 10:36 AM 0
Share

why cannot you use simple mouse down function than ray cast hit .when mouse is down inside the loop call that blinking function

avatar image wenhua · Jan 19, 2012 at 01:03 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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;
 
 
 
   }
 
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wenhua · Jan 19, 2012 at 01:40 AM 0
Share

yea it works thx again

avatar image wenhua · Jan 20, 2012 at 05:36 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges