• 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 panorama · Sep 13, 2011 at 05:35 PM · iosnetwork

[Network] Damage Not receive ?

Hi I'm got a problem with damages when i shoot to other character not happen it on See this my Machine Gun Code / This file is part of the Unity networking tutorial by M2H (http://www.M2H.nl) The original author of this code is Mike Hergaarden, even though some small parts are copied from the Unity tutorials/manuals. Feel free to use this code for your own projects, drop us a line if you made something exciting! / #pragma implicit #pragma downcast

var range = 100.0; var fireRate = 0.2; var force = 10.0; var damage = 5.0; var bulletsPerClip = 40; var clips = 10; var reloadTime = 0.5; private var hitParticles : ParticleEmitter; var muzzleFlash : Renderer;

var localPlayer : boolean = false; var localPlayerName : String = "";

private var bulletsLeft : int = 0; private var nextFireTime = 0.0; private var m_LastFrameShot = -1;

private var ammoText : String = ""; var btnTexture : Texture; var timer : float = 1; var timerMax : float = 1;

var mytrans : Transform;

function Start () { mytrans=transform;
localPlayerName=PlayerPrefs.GetString("playerName");

 hitParticles = GetComponentInChildren(ParticleEmitter);
 
 // We don't want to emit particles all the time, only when we hit something.
 if (hitParticles){
     hitParticles.emit = false;
 }
 bulletsLeft = bulletsPerClip;
 GetBulletsLeft();

}

function Update(){ if(!localPlayer){ return; } }
function OnGUI() {

         if(localPlayer){
     GUILayout.Space(20);
     GUILayout.Label("Ammo: "+ammoText);
     }

 
 if (GUI.RepeatButton(Rect(280, 280, 40, 40),btnTexture)){
     
 
     var direction = transform.TransformDirection(Vector3.forward);
     var hit : RaycastHit;
     timer += 1 * Time.deltaTime;
     
     if(timer >= timerMax) {
            Fire();
         }
         
     
         
         
                     
     
 }

}

function LateUpdate() {

     // We shot this frame, enable the muzzle flash
     if (m_LastFrameShot >= Time.frameCount-3) {
         
         //muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
         if(!localPlayer){
             muzzleFlash.enabled = true;
         }
         
         if (audio) {
             if (!audio.isPlaying)
                 audio.Play();
             audio.loop = true;
         }
     } else {
     // We didn't, disable the muzzle flash
         muzzleFlash.enabled = false;

         // Play sound
         if (audio)
         {
             audio.loop = false;
         }
     }

}

function Fire () {

 if (bulletsLeft == 0){
     return;
 }
 
 // If there is more than one bullet between the last and this frame
 // Reset the nextFireTime
 if (Time.time - fireRate > nextFireTime){
     nextFireTime = Time.time - Time.deltaTime;
 }
 
 
 // Keep firing until we used up the fire time
 while( nextFireTime < Time.time && bulletsLeft != 0) {
     var direction = transform.TransformDirection(Vector3.forward);
     var hit : RaycastHit;
 
             
     // Did we hit anything?
     if (Physics.Raycast (mytrans.position, direction, hit, range)) {
         FiredOneShot(true, hit.point, hit.normal );
         GetComponent(uLink.NetworkView).RPC("FiredOneShot",uLink.RPCMode.Others,false, hit.point, hit.normal); 
     
         // Send a damage message to the hit object            
         var settingsArray = new String[2];
         settingsArray[0]=damage+"";
         settingsArray[1]=localPlayerName;
     
         hit.collider.SendMessage("ApplyDamage", settingsArray, SendMessageOptions.DontRequireReceiver);    
     }
 
 bulletsLeft--;
 GetBulletsLeft();

 // Register that we shot this frame,
 // so that the LateUpdate function enabled the muzzleflash renderer for one frame
 m_LastFrameShot = Time.frameCount;
 //enabled = true;
 
 // Reload gun in reload Time        
 if (bulletsLeft == 0){
     Reload();        
 }    
 
 nextFireTime += fireRate;

 }    

}

@RPC function FiredOneShot (shotOwner : boolean, hitPoint : Vector3, hitNormal : Vector3) { // Apply a force to the rigidbody we hit //if (hit.rigidbody){ // hit.rigidbody.AddForceAtPosition(force * direction, hit.point); //}

     // Place the particle system for spawing out of place where we hit the surface!
     // And spawn a couple of particles
     if (hitParticles) {
         hitParticles.transform.position = hitPoint;
         hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);
         hitParticles.Emit();
     }

     m_LastFrameShot = Time.frameCount;

}

function Reload () { // Wait for reload time first - then add more bullets! yield WaitForSeconds(reloadTime);

 // We have a clip left reload
 if (clips > 0) {
     clips--;
     bulletsLeft = bulletsPerClip;
     if(localPlayer){
         ammoText=bulletsLeft+"/"+(clips*bulletsPerClip);
     }
 }

}

function GetBulletsLeft () { ammoText=bulletsLeft+"/"+(clips*bulletsPerClip); return bulletsLeft; }

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 roamcel · Sep 13, 2011 at 06:43 PM

Besides the wall of text, which is certainly discouraging, can it be that your problem is not related to the script but rather the scene?

For example, you must be sure that all your network objects have NETWORKVIEWS attached to them.

Do you have errors in the console?

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 panorama · Sep 13, 2011 at 07:11 PM 0
Share

I have got some message from console it's warn that

You probably need to add a Renderer to the game object "Tank5.00(Clone)". Or your script needs to check if the component is attached before using it. PlayerScript.Awake () (at Assets/PlayerScript.js:27) UnityEngine.Object:Instantiate(Object, Vector3, Quaternion) uLink.#=qqT$rPWFcolRJHXbPnI1qCZEj6emXYABQDs5V0gt16Gs=:#=qhuW$IYdOaY$$anonymous$$SagU$$anonymous$$I7HR3q5vSrwFBzYbuhy5iB0SQ8upIt$bfTDbQ3ITt8B3qbRL(String, Vector3, Quaternion) #=q3$$anonymous$$kh2YJ7VL5x4p3$$anonymous$$2TfxXGwQjawaOk_2BU$$anonymous$$A$$anonymous$$9LU454=:#=qSkSGQyD8A_EQAgP7hSmDtQ==(String, Vector3, Quaternion) #=qqva8X95ZWilPd_q99fEBh_hOy_LDPvI56G88WbYgZ78=:#=qEpqc3SEc1$$anonymous$$9lfGd4FRYO2w==(String, NetworkViewID, NetworkPlayer, Vector3, Quaternion, String, String, String, BitStream, #=q$Lrg49si3cBPuhT$wiChSQ==) #=quX6_ig6h2lbCTpoDHPI7cmso3Xxk0$$anonymous$$rOp25xB$bW2rg=:#=qFfJI2cWc9JLWCeNnHeriUw==(NetworkViewID, NetworkPlayer, String, String, String, Vector3, Quaternion, Int32, Object[]) #=quX6_ig6h2lbCTpoDHPI7cmso3Xxk0$$anonymous$$rOp25xB$bW2rg=:#=qwgiB2pDvQvdgwP67ZDH2LQ==(NetworkPlayer, String, String, String, Vector3, Quaternion, Int32, Object[]) #=quX6_ig6h2lbCTpoDHPI7cmso3Xxk0$$anonymous$$rOp25xB$bW2rg=:#=qH41LbPalhqyRhh$$anonymous$$rO63DOA==(NetworkPlayer, String, Vector3, Quaternion, Int32, Object[]) #=quX6_ig6h2lbCTpoDHPI7cmso3Xxk0$$anonymous$$rOp25xB$bW2rg=:#=qPFOHb_3H5Gk_$btrwnd5Rw==(String, Vector3, Quaternion, Int32, Object[]) #=q3$$anonymous$$kh2YJ7VL5x4p3$$anonymous$$2TfxXGwQjawaOk_2BU$$anonymous$$A$$anonymous$$9LU454=:#=qII7OLSJ9Jbe6Z4I_xDQjNQ==(Object, Vector3, Quaternion, Int32, Object[]) uLink.Network:Instantiate(Object, Vector3, Quaternion, Int32, Object[]) GameSetup:OnNetworkLoadedLevel() (at Assets/GameSetup.js:111) UnityEngine.GameObject:Send$$anonymous$$essage(String, Send$$anonymous$$essageOptions) GameSetup:Awake() (at Assets/GameSetup.js:42)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Damage does not receive on my Tank[Network] 1 Answer

NullReferenceException: Object reference not set to an instance of an object 0 Answers

How much it cost Union to Port to iOS? 1 Answer

u3dxt causing failed validation 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