Hit Collider issue ?

Hey guys,

I am working on my gun script and basically when i shoot objects i want particles to come out. For example if i shoot wood it will shoot out a wood particles. Now i have the basic done basically i have said if the hit variable its a rigid body display the sparks. Now how do i tell the hit to only display different particles when it hits objects with tags. For example if i hit a player called DING and i say hit.collider.gameObjec.tag == “DING” then do something. Now this is not working for me can someone please help me :slight_smile: thank you so much in advance :slight_smile:

Please note the code that does the above is in ** Broken up using the lines ** :slight_smile:

Thank you once again MCHALO

		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;
		
     			//var PlayerPos : Transform;
     			//var RadarCam : Transform;
     			//	//var Finder: Transform;
     			//var CamFinder: Transform;
     			public var hitParticlesBlood : ParticleEmitter;
  
      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;
		    hitParticlesBlood.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 * 2000000, 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.tag == "Enemy"){
				
				if( hitParticlesBlood){
				
				hitParticlesBlood.transform.position = hit.point;
				hitParticlesBlood.transform.localRotation =Quaternion.FromToRotation(Vector3.forward, hit.normal);
				hitParticlesBlood.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);


}

Its ok i have found out the problem i can not uses tag it is supposed to be gameObject.CompareTag

Thank you for your time :slight_smile: