Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 $$anonymous$$ · Jul 21, 2013 at 06:30 AM · functionshootingreload

How To Disable/Enable Function

I want, if reload then not shot, How to do this? This My Shoot And Reload Script.

 var Effect : Transform;
 var MuzzleFlash : GameObject;
 var damage = 100;
 
 function Start(){
 
     animation.wrapMode = WrapMode.Loop;
     
     animation["Reload"].wrapMode = WrapMode.ClampForever;
     animation["Default"].wrapMode = WrapMode.Once;
     
     animation["Reload"].layer = 1;
 
     animation.CrossFade("Default");
 }
 
 function Update () {
     
     Shoot();
     
     Reload();
 
 }
 
 function Shoot(){
     
     var hit : RaycastHit;
     var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
               
     if (Input.GetMouseButtonDown(0))
     {          
         Physics.Raycast (ray, hit, 100);
         
         MuzzleFlash.SetActive(true);
                         
         var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
         Destroy(particleClone.gameObject, 0.7);
             
         Debug.Log("Mouse Down"+Time.time);
         
     }else if(Input.GetMouseButtonUp(0)){
     
         MuzzleFlash.SetActive(false);
               
         Debug.Log("Mouse Up"+Time.time);
     }
     
 }
 
 function Scope(){
 
     if (Input.GetMouseButtonDown(1)){
     
      
                 
     }else if(Input.GetMouseButtonUp(1)){
     
         
     }
 }
 
 function Reload(){
 
     if(Input.GetKeyDown("r")){
          
          animation.CrossFade("Reload");
          
     }else if(Input.GetKeyUp("r")){
     
         yield WaitForSeconds(2);
         animation.Stop();
         animation.CrossFade("Default");
         
             
     }
 }


thanks before...

Comment
Add comment
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

2 Replies

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

Answer by xikky · Jul 21, 2013 at 07:19 AM

You can declare a boolean variable and set it to false initially. Then you switch it to true when reload is started and back to false when reload is finished. Then wrap the Shoot() function inside this boolean to execute Shoot() only when the declared boolean is false.

Comment
Add comment · 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
0

Answer by SuhaimKhalid · Jan 27, 2021 at 08:57 PM

You can use boolean for example shootclick and put all code of shoot function in if shootclick is true like this

function Shoot(){ if(shootclick==true) ``{ var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));

  if (Input.GetMouseButtonDown(0))
  {          
      Physics.Raycast (ray, hit, 100);
      
      MuzzleFlash.SetActive(true);
                      
      var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
      Destroy(particleClone.gameObject, 0.7);
          
      Debug.Log("Mouse Down"+Time.time);
      
  }else if(Input.GetMouseButtonUp(0)){
  
      MuzzleFlash.SetActive(false);
            
      Debug.Log("Mouse Up"+Time.time);
  }
  

} }

Comment
Add comment · 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

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

16 People are following this question.

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

Related Questions

Wait for reload to finish? 1 Answer

reloading script problem 0 Answers

Function reload doesnt work 1 Answer

Problem with Ammo/Shoot script 2 Answers

call a function at a specific frame of animation using mecanin 2 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