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
1
Question by Samuel411 · Nov 15, 2013 at 12:53 AM · rigidbodyraycastmultiplayercounterkills

Multiplayer Kill Counter?

Hello, I need help counting the kills the player gets. I have grenades (damage is based on if anyone is in a radius they receive damage and if anything has a rigidbody it will be moved), Shooting (raycast), and Knifing (raycast). This is a multiplayer fps and players are on teams. I need to see who fired the raycast that ended a players life and add that to the scoreboard, start counting for a killstreak, and award xp. As soon as I know how to see who fired the raycast I could do it. I brainstormed a bit and figured out I need to immediately fire back a raycast from who ever was hit with a boolean that says whether or not the player they shot died. I need help sending back the raycast with the right rotation and position. If their is a better way to do this please tell me. Their will be more than one player in the games meaning I could not use static variables.

My knife script -

 var QuickKnife : GameObject;
 var KnifeAnim : String;
 var KnifeSpeed : float = 2;
 
 var CanKnife : boolean = true;
 
 var Sound : AudioClip;
 
 var Force : float = 1000;
 var Range : float = 5;
 
 var BDamage : float = 100;
 var RDamage : float = 100;
 
 var SpawnPoint : Transform;
 
 var BloodImpact : Transform;
 var DirtImpact : Transform;
 var ConcreteImpact : Transform;
 var MetalImpact : Transform;
 var WoodImpact : Transform;
 var WaterImpact : Transform;
 var GlassImpact : Transform;
 
 function Start () {
      
 }
 
 function Update () {
      if(SwitchingWeapons.CanSwitch){
      if(Input.GetButton("Knife")){
         Knife();
         animation[KnifeAnim].speed = (animation[KnifeAnim].clip.length/KnifeSpeed);
         animation.Play(KnifeAnim);
      }
    }
 }
 
 function Knife(){
      SwitchingWeapons.CanSwitch = false;
      Gun.CanFire = false;
      Raycast();
      audio.PlayOneShot(Sound);
      SendMessageUpwards("KnifeSound",SendMessageOptions.DontRequireReceiver);
      yield WaitForSeconds(KnifeSpeed);
      gameObject.SetActiveRecursively(false);
      if(SwitchingWeapons.PrimaryHeld){
      SwitchingWeapons.PrimarySwitch = true;
      }
      if(SwitchingWeapons.SecondaryHeld){
      SwitchingWeapons.SecondarySwitch = true;
      }
      if(SwitchingWeapons.KnifeHeld){
      SwitchingWeapons.KnifeSwitch = true;
      }
      Gun.CanFire = true;
      SwitchingWeapons.CanSwitch = true;
 }
 
 function Raycast(){
     yield WaitForSeconds(0.2);
     
     var hit : RaycastHit;
     var direction : Vector3  = SpawnPoint.TransformDirection(Vector3.forward);
          
     Debug.DrawRay(SpawnPoint.position , direction * Range , Color.yellow);
     
     if(Physics.Raycast(SpawnPoint.position , direction , hit, Range)){
        var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
        
        if (hit.rigidbody){
          hit.rigidbody.AddForceAtPosition(Force * direction, hit.point);
        }
        if(hit.collider.tag == "Dead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
        }
        
        
        if(hit.collider.tag == "RPlayer"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RLegs"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BArms"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RChest"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RHead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           Crosshair.HitMarker = true;
        }
        
        
        if(hit.collider.tag == "BPlayer"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BLegs"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BArms"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BChest"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BHead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        
        
        if(hit.collider.tag == "Dirt"){
           Network.Instantiate(DirtImpact, hit.point, hitRotation, 1);
        }
        if(hit.collider.tag == "Metal"){
           Network.Instantiate(MetalImpact, hit.point, hitRotation, 1);
        }
        if(hit.collider.tag == "Concrete"){
           Network.Instantiate(ConcreteImpact, hit.point, hitRotation, 1);
        }
        if(hit.collider.tag == "Water"){
           Network.Instantiate(WaterImpact, hit.point, hitRotation, 1);
        }
        if(hit.collider.tag == "Wood"){
           Network.Instantiate(WoodImpact, hit.point, hitRotation, 1);
        }
        
        if(hit.collider.tag == "Glass"){
           Network.Instantiate(GlassImpact, hit.point, hitRotation, 2);
           hit.collider.SendMessageUpwards("AdjustHealth", 100,SendMessageOptions.DontRequireReceiver);
        }
     }
 }

My gun script -

 #pragma strict
 
 var BulletShell : Rigidbody;
 var ShellSpawnPoint : Transform;
 var SpawnPoint : Transform;
 var Muzzle : Transform;
 var MuzzleFlashh : GameObject;
 var MuzzleSmoke : GameObject;
 
 var Style : GUIStyle;
 
 var Name : String;
 
 var Auto : boolean = false;
 var ThreeRoundBurst : boolean = false;
 var Shotgun : boolean = false;
 var SingleReload : boolean = false;
 var DuelWield : boolean = false;
 static var DuelWieldStatic : boolean = false;
 static var CanFire : boolean = true;
 private var CanReload : boolean = true;
 static var IsReloading : boolean = false;
 static var IsReloading2 : boolean = false;
 static var IsShooting : boolean = false;
 static var Hitwall : boolean = false;
 
 private var MaxRandomness2 : float = 0.8f;
 var MaxRandomness : float = 0.8f;
 var MinRandomness : float = 0.0f;
 
 var FireRate : float = 0.1;
 static var FireRRate : float = 0.1;
 var ReloadTime : float = 2;
 static var ReloadTTime : float;
 var Bullets : float = 32;
 private var Bullets2 : float = 32;
 private var Bullets3 : float = 32;
 var UsedBullets : float = 0;
 var MaxBullets : float = 154;
 var Range : float = 1000;
 var Force : float = 1000;
 
 var BloodImpact : Transform;
 var DirtImpact : Transform;
 var ConcreteImpact : Transform;
 var MetalImpact : Transform;
 var WoodImpact : Transform;
 var WaterImpact : Transform;
 var GlassImpact : Transform;
 
 var WoodHole : Transform[];
 var MetalHole : Transform[];
 var ConcreteHole : Transform[];
 var GlassHole : Transform[];
 
 var BDamage : float = 10;
 var BLegDamage : float = 8;
 var BArmDamage : float = 8;
 var BChestDamage : float = 20;
 var BHeadDamage : float = 70;
 
 var RDamage : float = 10;
 var RLegDamage : float = 8;
 var RArmDamage : float = 8;
 var RChestDamage : float = 20;
 var RHeadDamage : float = 70;
 
 var ShootSound : AudioClip;
 var ReloadSound : AudioClip;
 var ReloadBeginSound : AudioClip;
 var ReloadEndSound : AudioClip;
 
 
 function Start () {
      MaxRandomness2 = MaxRandomness;
      Bullets2 = Bullets;
      Bullets3 = Bullets;
      ReloadTTime = ReloadTime;
      FireRRate = FireRate;
      ReloadTTime -= 0.02;
      DuelWieldStatic = DuelWield;
 }
 
 function Update () {
 if(IsReloading){
    CanFire = false;
 }
 
 WallCheck();
 if(Hitwall){
    MaxRandomness = 0.1;
 }else{
    MaxRandomness = MaxRandomness2;
 }
 if(Bullets > 0){
 
 if(Auto == false){
     if(Input.GetButtonDown("Shoot")){
     if((Bullets == 0)&& MaxBullets == 0){
     SwitchingWeapons.SecondarySwitch = true;
     }else{
     Fire();
     if(Bullets == 0){
        ReloadNoAmmo();
       }
     }
   }
 }
 
 if(Auto == true){
     if(Input.GetButton("Shoot")){
     if((Bullets == 0)&& MaxBullets == 0){
     SwitchingWeapons.SecondarySwitch = true;
     }else{
     Fire();
     if(Bullets == 0){
        ReloadNoAmmo();
       }
     }
   }
 }
 }
 
 if(Auto == false && DuelWield == true){
     if(Input.GetButtonDown("DuelWieldShoot")){
     if((Bullets == 0)&& MaxBullets == 0){
     SwitchingWeapons.SecondarySwitch = true;
     }else{
     Fire();
     if(Bullets == 0){
        ReloadNoAmmo();
       }
     }
   }
 }
 
 if(Input.GetButtonDown("Reload")){
 if(!IsReloading){
     Reload();
   }
 } 
   if(Bullets == Bullets3){
   CanReload = false;
   }
   else{
   CanReload = true;
   }
   if(Bullets <= 0){
   Bullets = 0;
   CanFire = false;
   }
   if(MaxBullets <= 0){
   CanReload = false;
   }
   if(ThreeRoundBurst){
   Auto = false;
   }
 }
 
 function ReloadNoAmmo(){
      yield WaitForSeconds(FireRate);
      Reload();
 }
 
 function Fire(){
 if((CanFire == true)&& !Aiming.IsSprinting){
     IsShooting = true;
     CanSwitch = false;
     CanFire = false;
     Recoil.recoil += 0.1;
     
     
     
     if(ThreeRoundBurst){
        for(i = 0; i < 3; i++){
            RayCast();
            yield WaitForSeconds(0.1);
            UsedBullets += 1;
            Bullets -= 1;
            Bullets2 -= 1;
            audio.PlayOneShot(ShootSound);
            if(Name == "M4A3"){
                 SendMessageUpwards("ShootM4A3",SendMessageOptions.DontRequireReceiver);
            }
            if(Name == "Remmington"){
                  SendMessageUpwards("ShootRemmington",SendMessageOptions.DontRequireReceiver);
            }
            if(Name == "M9"){
                  SendMessageUpwards("ShootM9",SendMessageOptions.DontRequireReceiver);
            }
            if(Name == "M40A3"){
                  SendMessageUpwards("ShootM40A3",SendMessageOptions.DontRequireReceiver);
            }
            
            BroadcastMessage("FireAnim"); 
        }
     }
     
     if(Shotgun){
        for(i = 0; i < 4; i++){
            RayCast();
        }
        UsedBullets += 1;
        Bullets -= 1;
        Bullets2 -= 1;
        audio.PlayOneShot(ShootSound);
        if(Name == "M4A3"){
             SendMessageUpwards("ShootM4A3",SendMessageOptions.DontRequireReceiver);
        }
        if(Name == "Remmington"){
              SendMessageUpwards("ShootRemmington",SendMessageOptions.DontRequireReceiver);
        }
        if(Name == "M9"){
        SendMessageUpwards("ShootM9",SendMessageOptions.DontRequireReceiver);
        }
        if(Name == "M40A3"){
              SendMessageUpwards("ShootM40A3",SendMessageOptions.DontRequireReceiver);
        }
        BroadcastMessage("FireAnim"); 
     }
     
     if((!Shotgun)&& !ThreeRoundBurst){
     audio.PlayOneShot(ShootSound);
     if(Name == "M4A3"){
        SendMessageUpwards("ShootM4A3",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "Remmington"){
        SendMessageUpwards("ShootRemmington",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M9"){
        SendMessageUpwards("ShootM9",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M40A3"){
        SendMessageUpwards("ShootM40A3",SendMessageOptions.DontRequireReceiver);
     }
     RayCast();
     UsedBullets += 1;
     Bullets -= 1;
     Bullets2 -= 1;
     BroadcastMessage("FireAnim"); 
     }
     MuzzleFlash();
     var shot = Network.Instantiate(BulletShell, ShellSpawnPoint.transform.position, Quaternion.identity, 0);
     shot.rigidbody.AddForce(transform.up * 100);
     yield WaitForSeconds(FireRate);
     CanFire = true;
     CanSwitch = true;
     IsShooting = false;
    }
  }
   
 
 function Reload(){
 if((CanReload == true)&& !Aiming.IsSprinting){
     Aiming.CanSprint = false;
     Aiming.CanAim = false;
     IsReloading = true;
     SwitchingWeapons.CanSwitch = false;
     CanReload = false;
     CanFire = false;
 
     //Single Reload
     
     if(SingleReload){
     audio.PlayOneShot(ReloadBeginSound);
     if(Name == "M4A3"){
        SendMessageUpwards("ReloadBeginM4A3",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "Remmington"){
        SendMessageUpwards("ReloadBeginRemmington",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M9"){
        SendMessageUpwards("ReloadBeginM9",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M40A3"){
        SendMessageUpwards("ReloadBeginM40A3",SendMessageOptions.DontRequireReceiver);
     }
     BroadcastMessage("SingleReloadBeginAnim");
     yield WaitForSeconds(0.65);
     while(UsedBullets >= 1){
     BroadcastMessage("ReloadAnim",SendMessageOptions.DontRequireReceiver);
     audio.PlayOneShot(ReloadSound);
     if(Name == "M4A3"){
        SendMessageUpwards("ReloadM4A3",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "Remmington"){
        SendMessageUpwards("ReloadRemmington",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M9"){
        SendMessageUpwards("ReloadM9",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M40A3"){
        SendMessageUpwards("ReloadM40A3",SendMessageOptions.DontRequireReceiver);
     }
     yield WaitForSeconds(ReloadTime);
     yield WaitForSeconds(0.05);
     UsedBullets -= 1;
     Bullets += 1;
     MaxBullets -= 1;
     if(MaxBullets == 0){
     UsedBullets = 0;
     }
     }
     audio.PlayOneShot(ReloadEndSound);
     if(Name == "M4A3"){
        SendMessageUpwards("ReloadEndM4A3",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "Remmington"){
        SendMessageUpwards("ReloadEndRemmington",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M9"){
        SendMessageUpwards("ReloadEndM9",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M40A3"){
        SendMessageUpwards("ReloadEndM40A3",SendMessageOptions.DontRequireReceiver);
     }
     BroadcastMessage("SingleReloadEndAnim");
     }else{
     
     //Normal Reload
     
     Bullets = 0;
     BroadcastMessage("ReloadAnim");
     audio.PlayOneShot(ReloadSound);
     if(Name == "M4A3"){
        SendMessageUpwards("ReloadM4A3",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "Remmington"){
        SendMessageUpwards("ReloadRemmington",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M9"){
        SendMessageUpwards("ReloadM9",SendMessageOptions.DontRequireReceiver);
     }
     if(Name == "M40A3"){
        SendMessageUpwards("ReloadM40A3",SendMessageOptions.DontRequireReceiver);
     }
     yield WaitForSeconds(ReloadTime);
     if(MaxBullets > UsedBullets){
     Bullets += Bullets2;
     Bullets += UsedBullets;
     MaxBullets -= UsedBullets;
     }
     else{
     Bullets += MaxBullets;
     MaxBullets -= MaxBullets;
     }
     }
     Bullets2 = Bullets;
     UsedBullets = 0;
     CanReload = true;
     SwitchingWeapons.CanSwitch = true;
     CanFire = true;
     IsReloading = false;
     Aiming.CanAim = true;
     Aiming.CanSprint = true;
   }
 }
 
 function MuzzleFlash () {
      var Flash : GameObject = Network.Instantiate(MuzzleFlashh, Muzzle.transform.position, Muzzle.transform.rotation, 0);
      Flash.transform.parent = Muzzle;
      var Smoke : GameObject = Network.Instantiate(MuzzleSmoke, Muzzle.transform.position, Muzzle.transform.rotation, 0);
      Smoke.transform.parent = Muzzle;
 }
 
 function RayCast () {
     if(!Input.GetMouseButton(1)){
        ShootPosition = Vector3(Random.Range(MinRandomness, MaxRandomness), Random.Range(MinRandomness, MaxRandomness), Random.Range(MinRandomness, MaxRandomness));
     }else{
        ShootPosition = Vector3(0, 0, 0);
     }
     
     var hit : RaycastHit;
     var direction : Vector3  = SpawnPoint.TransformDirection(Vector3.forward);
          
     Debug.DrawRay(SpawnPoint.position + ShootPosition, direction * Range , Color.yellow);
     
     if(Physics.Raycast(SpawnPoint.position + ShootPosition, direction , hit, Range)){
        var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
        
        yield WaitForSeconds(0.3);
        
        if (hit.rigidbody){
           hit.rigidbody.AddForceAtPosition(Force * direction, hit.point);
        }
        
        if(hit.collider.tag == "Dead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
        }
        
        if(SpawnManager.CurTeam == "Blue"){
        
        if(hit.collider.tag == "RPlayer"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RLegs"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RLegDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RLegDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RArms"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RArmDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RArmDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RChest"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RChestDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RChestDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "RHead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", RHeadDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RHeadDamage);
           Crosshair.HitMarker = true;
        }
        }
        
        if(SpawnManager.CurTeam == "Red"){
        
        if(hit.collider.tag == "BPlayer"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BLegs"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BLegDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BLegDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BArms"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BArmDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BArmDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BChest"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BChestDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BChestDamage);
           Crosshair.HitMarker = true;
        }
        if(hit.collider.tag == "BHead"){
           Network.Instantiate(BloodImpact, hit.point, hitRotation, 1);
           hit.collider.SendMessageUpwards("AdjustHealth", BHeadDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BHeadDamage);
           Crosshair.HitMarker = true;
        }
        }
        
        
        if(hit.collider.tag == "Dirt"){
           Network.Instantiate(DirtImpact, hit.point, hitRotation, 2);
        }
        if(hit.collider.tag == "Metal"){
           var MetalBulletHole = Random.Range(0,(MetalHole.length - 1));
           Network.Instantiate(MetalImpact, hit.point, hitRotation, 2);
           var tmpObject : Transform = Network.Instantiate(MetalHole[MetalBulletHole], hit.point, hitRotation, 2);
           tmpObject.transform.parent = hit.transform;
        }
        if(hit.collider.tag == "Concrete"){
           var ConcreteBulletHole = Random.Range(0,(ConcreteHole.length - 1));
           Network.Instantiate(ConcreteImpact, hit.point, hitRotation, 2);
           var tmpObject1 : Transform = Network.Instantiate(ConcreteHole[ConcreteBulletHole], hit.point, hitRotation, 2);
           tmpObject1.transform.parent = hit.transform;
        }
        if(hit.collider.tag == "Water"){
           Network.Instantiate(WaterImpact, hit.point, hitRotation, 2);
        }
        if(hit.collider.tag == "Wood"){
           var WoodBulletHole = Random.Range(0,(WoodHole.length - 1));
           Network.Instantiate(WoodImpact, hit.point, hitRotation, 2);
           var tmpObject2 : Transform = Network.Instantiate(WoodHole[WoodBulletHole], hit.point, hitRotation, 2);
           tmpObject2.transform.parent = hit.transform;
        }
        
        if(hit.collider.tag == "Glass"){
           var GlassBulletHole = Random.Range(0,(GlassHole.length - 1));
           Network.Instantiate(GlassImpact, hit.point, hitRotation, 2);
           var tmpObject3 : Transform = Network.Instantiate(GlassHole[GlassBulletHole], hit.point, hitRotation, 2);
           tmpObject3.transform.parent = hit.transform;
           hit.collider.SendMessageUpwards("AdjustHealth", 30,SendMessageOptions.DontRequireReceiver);
        }
        
        if(hit.collider.tag == "Shard"){
           Network.Instantiate(GlassImpact, hit.point, hitRotation, 2);
        }
     }
 }
 function WallCheck(){
     var hit : RaycastHit;
     var direction : Vector3  = SpawnPoint.TransformDirection(Vector3.forward);
     
     Debug.DrawRay(SpawnPoint.position, direction * 2.3 , Color.yellow);
     
     if(Physics.Raycast(SpawnPoint.position, direction , hit, 2.3)){
        Hitwall = true;
     }else{
        Hitwall = false;
     }
 }
 
 function OnGUI(){
     GUI.Label (Rect (Screen.width/1 - 150, Screen.height/1 - 50, 100, 50), Bullets + "/" + MaxBullets, Style);
     GUI.Label (Rect (Screen.width/1 - 150, Screen.height/1 - 82, 400, 100), Name, Style);
 }

Explosion script -

 #pragma strict
 
 var radius = 5.0;
 var power = 10.0;
 var RDamage : float = 100;
 var BDamage : float = 100;
 var RDamageSelf : float = 100;
 var BDamageSelf : float = 100;
     
     
     function Start () {
         AddDeadForce();
         // Applies an explosion force to all nearby rigidbodies
         var explosionPos : Vector3 = transform.position;
         var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
         
         for (var hit : Collider in colliders) {
             if (!hit){
                 continue;
             }
             
             if (hit.rigidbody){
                 hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
             }
        if(hit.collider.tag == "BLegs"){
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
        }
        if(hit.collider.tag == "BArms"){
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
        }
        if(hit.collider.tag == "BChest"){
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
        }
        if(hit.collider.tag == "BHead"){
           hit.collider.SendMessageUpwards("AdjustHealth", BDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
        }
        if(hit.collider.tag == "BPlayer"){
           hit.collider.SendMessageUpwards("AdjustHealth", BDamageSelf,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,BDamage);
        }
        
        
        if(hit.collider.tag == "RLegs"){
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
        }
        if(hit.collider.tag == "RArms"){
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
        }
        if(hit.collider.tag == "RChest"){
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
        }
        if(hit.collider.tag == "RHead"){
           //hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
           hit.collider.SendMessageUpwards("AdjustHealth", RDamage,SendMessageOptions.DontRequireReceiver);
        }
        if(hit.collider.tag == "RPlayer"){
           hit.collider.SendMessageUpwards("AdjustHealth", RDamageSelf,SendMessageOptions.DontRequireReceiver);
           //hit.transform.gameObject.networkView.RPC("AdjustHealth", RPCMode.All,RDamage);
        }
        
        if(hit.collider.tag == "Glass"){
           hit.collider.SendMessageUpwards("AdjustHealth", 100,SendMessageOptions.DontRequireReceiver);
        }
         }
     }
     
     function AddDeadForce(){
          yield WaitForSeconds(0.1);
          // Applies an explosion force to all nearby rigidbodies
         var explosionPos : Vector3 = transform.position;
         var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
         
         for (var hit : Collider in colliders) {
             if (!hit){
                 continue;
             }
             
             if (hit.rigidbody){
                 hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
             }
          }
     }
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

Answer by HuskyPanda213 · Nov 15, 2013 at 04:30 AM

Best solution have a RPC that takes a networkplayer value, send it to a non-network-instantiated object like one where the netcode is. Compare the networkplayer value with your network.player, if it is the same, reward XP or coins or something. This is what I use, it works well.

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 Samuel411 · Nov 15, 2013 at 12:57 PM 0
Share

Thank you. It seems like a better solution and easier than what I was thinking of. Also what if there is about 12 people in the match?

avatar image HuskyPanda213 · Nov 15, 2013 at 08:19 PM 0
Share

It should work with twelve or more people, also just stating the code should be executed like what I did, here(this is for a photon game, kinda like planetside 2. Also you should only have like one shoot method, the code is hard to read.):

[RPC] void HitByBullet(int d,PhotonPlayer pl){ if(photonView.is$$anonymous$$ine){ Health-=d; if(Health < 1){ photonView.RPC("$$anonymous$$illPlayer",PhotonTargets.All); GameObject network = GameObject.FindGameObjectWithTag("Network"); network.GetComponent<$$anonymous$$yNetwork$$anonymous$$anagerPhoton>().photonView.RPC("Player$$anonymous$$illedPlusInfo",PhotonTargets.All,pl); } } }

avatar image
0

Answer by gajdot · Nov 15, 2013 at 01:44 PM

You should only cast the ray from the owner and if it hits somebody send over and RPC that the target got hit by attacker. There is a tutorial from Gamer To Game Developer you can find on YouTube about creating a multi player game. There you can grasp the basic how to create a kill counter. He uses particles if I can remember, but you can use raycast just as well.

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

18 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 avatar image avatar image

Related Questions

3rd person carrying objects,3rd person picking up objects 0 Answers

[CLOSED]RaycastAll find closest hit 2 Answers

remove forward component from velocity vector 2 Answers

How to make a ball stay in the air longer when force is added? 1 Answer

Holding object not working. Raycast, and first person. 1 Answer


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