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 Rudstu · Apr 12, 2013 at 08:57 PM · raycastfpsfire

Swich fire button form F to LMB

in this script the fire button is on F but i want it on LMB but i dont know how. can somone helt me pliz?

     var Range : float = 1000;
     
     var Force : float = 1000;
     
     var Clips : int = 20;
     
     var BulletPerClip : int = 60;
     
     var RelaodTime : float = 3.3;
     
        var Damage : int = 10;
        
     var MoveSpeed: float = 1;
     
         var BulletsLeft : int = 0;
         
             var ShootTimer : float = 0;
             
             
             
             var ShootCooler : float = 0.5;
             
             public var ShootAudio : AudioClip;
             
             public var ReloadAudio : AudioClip;
             
             public var muzzleFlash : ParticleEmitter;
             
             public var hitParticles : ParticleEmitter;
             
             public var muzzleFlashTimer : float = 0;
              
             public var KeyCooler : float = 0.5;
             
                public var KeyTimer : float = 0;
             
             public var muzzleFlashCooler : float = 0.5;
             
             public var Lights1 : GameObject;
             
             public var Lights2 : GameObject ;
             
             public var Lights3 : GameObject;
             
             public var BloodEffect : ParticleEmitter;
     
               public var BloodEffectMain: ParticleEmitter;
     
     
     
              //var PlayerPos : Transform;
              //var RadarCam : Transform;
              //    //var Finder: Transform;
              //var CamFinder: Transform;
              
  

function Start(){

// PlayerPos.rotation = Quaternion.Euler(0,96.93118,0); // PlayerPos.position = Finder.position; //RadarCam.position = CamFinder.position;

     BulletsLeft = BulletPerClip;
     
     
     muzzleFlash.emit = false;
     
     
     DefaultPos = transform.localPosition;
     
     hitParticles.emit = false;
     
     BloodEffect.emit = false;
     BloodEffectMain.emit = false;
     
       
  

}

function Update () {

//PlayerPos.rotation = mainPos.rotation; //PlayerPos.position = Finder.position; //RadarCam.position = CamFinder.position;

if( KeyTimer > 0){

  KeyTimer -= Time.deltaTime;
   

}

if( KeyTimer < 0){

  KeyTimer= 0;
   

}

if( muzzleFlashTimer > 0){

  muzzleFlashTimer -= Time.deltaTime;

MuzzleFlash(); }

if( muzzleFlashTimer < 0){

  muzzleFlashTimer = 0;
 

}

if( ShootTimer > 0){

          ShootTimer -= Time.deltaTime;

}

if(ShootTimer < 0){

                ShootTimer = 0;
               
               }
               
          if( KeyTimer == 0){
         if(Input.GetKey(KeyCode.F) && BulletsLeft ){
         
         if( ShootTimer  == 0){
         
         PlayShootAudio();
         
          
             RayShoot();
              
             
                
             ShootTimer  = ShootCooler;
             KeyTimer = KeyCooler;
             
             }
             
                 if( muzzleFlashTimer == 0){
              
               muzzleFlashTimer = muzzleFlashCooler;   
                     MuzzleFlash ();    

}
}

} }

function MuzzleFlash (){

if( muzzleFlashTimer > 0){

     muzzleFlash.emit= false;
        
        Lights1.active = false;
        Lights2.active = false;
        Lights3.active = false;
           


} if( muzzleFlashTimer == muzzleFlashCooler){

   muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360 , Vector3.forward);

      muzzleFlash.emit = true;
        
         Lights1.active = true;
        Lights2.active = true;
        Lights3.active = true;

} }

function RayShoot (){

//GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Shoot"); //(if your player has animations then remove the // infront of the GameObject.Find and then //(replace your objetcs name there. and then the animation name) var hit : RaycastHit;

              var direction : Vector3  = transform.TransformDirection(Vector3.forward);
      
             Debug.DrawRay(transform.position , direction * Range , Color.blue);
             
             if(Physics.Raycast(transform.position , direction , hit, Range)){
             var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
             
             if(hit.rigidbody){
             
             if(hitParticles){
             
             hitParticles.transform.position = hit.point;
             
             hitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
             hitParticles.Emit();

                        
             hit.rigidbody.AddForceAtPosition( direction * Force , hit.point);
             hit.collider.SendMessageUpwards("ApplyDamage" , Damage , SendMessageOptions.DontRequireReceiver);
             }
             }
             
             if(hit.collider.gameObject.CompareTag("Enemy")){
             
                 if( BloodEffect ){
                 if( BloodEffectMain){
                 
                 BloodEffect.transform.position = hit.point;
                 BloodEffect.transform.position = hit.point;
                 
                 BloodEffect.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal);
                 BloodEffectMain.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal);
                 BloodEffect.Emit();
                 BloodEffectMain.Emit();
                 
             }
             }
             }
             }
             
             
             
             
             BulletsLeft --;
              
         
             if(BulletsLeft < 0){
             
             BulletsLeft = 0;
             
             }
             
             if( BulletsLeft == 0 ){
             
             Reload();
             
             
             }

             }
 


function Reload (){

     PlayReloadAudio();
     yield WaitForSeconds(0.2);
     
      //GameObject.Find("m1911pistoleReloadandShooting").animation.Play("Reload"); //(if your player has animations then remove the // infront of the GameObject.Find and then 
                                                                                      //(replace your objetcs name there. and then the animation name)
  yield WaitForSeconds( RelaodTime);
  
          if(Clips > 0){
          
             BulletsLeft = BulletPerClip; 
             
                        Clips -= 1;           
          

} }

function PlayShootAudio(){

     audio.PlayOneShot( ShootAudio);

}

function PlayReloadAudio(){

audio.PlayOneShot( ReloadAudio);

}

thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by RyanZimmerman87 · Apr 12, 2013 at 09:12 PM

I cant believe you posted your entire script for this answer :)

if (Input.GetButtonDown ("Fire1"))

Comment
Add comment · Show 1 · 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 Rudstu · Apr 12, 2013 at 09:28 PM 0
Share

i did what you posted but now it says "enemy is nit defined" do you know what to do now?

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

11 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

Related Questions

Drag Rigid Bodies First Person Controller.js 0 Answers

Display issues with GUI only showing details for last object in list. 2 Answers

Zombie FPS 2 Answers

Raycast Positioning 2 Answers

I have some code for the zombie AI but.... 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