Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AshwinTheGammer · Jun 13, 2018 at 03:01 AM · multiplayerphotonmultiplayer-networkingunity 4

[Photon] Cant give damage to other client and getting RPC error.

All codes are fine but I dont know why Im getting this error. So if you know something about this then please help me out! Im very grateful of you if you help me Here is health Script using UnityEngine; using System.Collections;

 public class Health : MonoBehaviour {
     
     public float hitPoints = 100f;
     float currentHitPoints;
     public Transform deadReplacement;
     bool isDead = false;
     // Use this for initialization
     void Start () {
         currentHitPoints = hitPoints;
     }
     
     [RPC]
     public void TakeDamage(float amt) {
         currentHitPoints -= amt;
         
         if(currentHitPoints <= 0) {
             Die();
         }
     }
     
     /*void OnGUI() {
         if( GetComponent<PhotonView>().isMine && gameObject.tag == "Player" ) {
             if( GUI.Button(new Rect (Screen.width-100, 0, 100, 40), "Suicide!") ) {
                 Die ();
             }
         }
     }*/
     [RPC]
     public void Die() {
         if( GetComponent<PhotonView>().instantiationId==0 ) {
             if (isDead)
                 return;
             isDead = true;
             
             if (deadReplacement) {
                 PhotonNetwork.Instantiate(this.deadReplacement.name, transform.position, Quaternion.identity, 0);
                 PhotonNetwork.Destroy(gameObject);
                 PhotonNetwork.Disconnect();
                 Application.LoadLevel(0);
             
         }
     
     }
 }
 }
 

Here is part of gun script (raycasting)

 public float minDamage;
 public float maxDamage;
 
 if (Physics.Raycast(ray, out hitInfo, range, thingsPlayerCanHit))
         {
             
             if (hitInfo.transform.gameObject.collider.tag == "Player") {
                 
                 hitInfo.transform.gameObject.GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.AllBuffered, Random.Range(minDamage, maxDamage));
 
             }
             
    error is: 

PhotonView with ID 1001 has no method "TakeDamage" marked with the [RPC](C#) or @RPC(JS) Property! Args: int32

Also i wanna instantiate a ragdoll when player dies and destroy it too! See in health script. Thats all! Thanks for help in advance!

Comment
Add comment · Show 1
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 ChristianSimon · Jun 14, 2018 at 03:15 PM 0
Share

Hi,

the RPC function needs to be implemented in the same class from where it is called. I'm currently not sure if this is the case here. If it is, you are fine in terms of this possible issue. The Die function does not require the [PunRPC] attribute header because it is not called as RPC (as far as I can see it is called directly). Destroying a networked object should only be done by the owner of the object, so you should surround this call with a photonView.is$$anonymous$$ine condition. I'm also not sure if the PhotonNetwork.Instantiate and the PhotonNetwork.Destroy calls are actually executed because you call PhotonNetwork.Disconnect directly after those other calls. To make sure that those messages are actually sent, add PhotonNetwork.SendOutgoingCommands before disconnecting from Photon.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Networking: Keep room alive without active players 0 Answers

Photon - How to spawn enemies that don't have a PhotonView and be synced with other clients 1 Answer

How many current players will I get daily if I have 10k installs 1 Answer

Synchronize multiple spawnpoints (Photon + RCC) 0 Answers

RPC to certain player in room using their nickname/userID 0 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