- Home /
How can i prevent a user from clicking morethan once on an instance of a gameobjectthat is busy spawning
How can i prevent a user from clicking and scoring twice on a given game object (prefab) that is busy being spawned. Im using tags. Im new to unity..So it's a bit like validation i suppose. At the moment when user clicks more than once, the score is incrementing.
 if(Input.Get$$anonymous$$ouseButtonDown(0))        //Linker mouse button
 {
     
     //print("$$anonymous$$ouse down Works");
     
var hit: RaycastHit; var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Get mouse position
     // Cast a Ray against all colliders in the scene
      if(Physics.Raycast(ray, hit, rayDistance))  
      {
           
           if(hit.transform.tag == objectTag1)
           {
           
               
               var enemyScript = hit.transform.GetComponent(scriptEnemy);
         
             // Reduce the number each click
             enemyScript.numberOfClicks -= 1;
              
             // condition to check that the object is at zero before adding the points to the score
             if(enemyScript.numberOfClicks <= 0)
             {
         
                 //Add points to our overall score
                 score += enemyScript.enemyPoints;
                 
                     
                 audio.PlayOneShot(blankSound);
                   
Not sure exactly what the problem is.
Can you simply set a bool on your enemyscript that is set to true once the object has been scored? Then check that bool before you check numberOfClicks.
Answer by Andres-Fernandez · May 26, 2014 at 07:48 AM
Just get the collider of the object being clicked and set enabled to false (then set it back to true when needed). Like this example in the docs.
Thank you...That's just what i needed. $$anonymous$$uch appreciated.
Your answer
 
 
             Follow this Question
Related Questions
Scoring System with Networking 1 Answer
Trying to sync score on multiplayer LAN game 0 Answers
Rotating object breaks limitations/Bounds 0 Answers
Scoring System 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                