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 PogyManTV · Jun 30, 2015 at 01:03 AM · networkingdestroymethodargumentsoverload

No overload for method "Destroy" takes 2 arguments?

Here's my script:

using UnityEngine; using System.Collections;

public class ItemPickup : MonoBehaviour {

 public AudioClip pickupSound;

 // Use this for initialization
 void Start () {
     StartCoroutine (DespawnTimer ());
 }
 
 // Update is called once per frame
 void Update () {
 
 }

 void OnTriggerEnter(Collider other)
 {
     if(other.tag == "Player")
     {
         if(gameObject.tag == "Item")
         {
             Inventory inventory = GameObject.Find("Inventory").GetComponent<Inventory>();

             if(this.gameObject.name.Equals("Wood"))
             {
                 audio.PlayOneShot(pickupSound);    
                 Network.Destroy(gameObject,pickupSound.length);
                 inventory.AddItem("Wood");
             
             }
         }
     }
 }

 IEnumerator DespawnTimer()
 {
     yield return new WaitForSeconds (120);
     Destroy (gameObject);
 }

}

If i delete network from network.destroy the error gone but i need network.destroy but cannot figure out what is wrong with this script ://

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
1

Answer by Landern · Jun 30, 2015 at 01:05 AM

There isn't a Network.Destroy that takes two parameters/arguments. It takes one for both exposed methods. This is clearly detailed in the documentation.

 public static void Destroy(NetworkViewID viewID)

or

 public static void Destroy(GameObject gameObject)

You're trying to apply some destroy in N amount of time. Network.Destroy isn't like Object.Destroy which does allow you to do that.

So in the end the error is completely correct.

Comment
Add comment · Show 6 · 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 PogyManTV · Jun 30, 2015 at 11:09 AM 0
Share

Ok thanks for quick replay (: but i added public static void Destroy(NetworkViewID viewID) to the script but another error appears telling me folowing: Item.Pickup.Destroy(NetworkView) must have a body because it is not marked abstract, extern or partial :/ Tired of this search whole internet how to solve this problem but without solution :/

avatar image Dave-Carlile · Jun 30, 2015 at 11:34 AM 0
Share

I think you misunderstood. This line...

 Network.Destroy(gameObject,pickupSound.length);


See the comma? Why are you passing pickupSound.length? In fact, looking at the documentation for Network.Destroy, why are you passing gameObject? The function expects a NetworkViewID.

avatar image tanoshimi · Jun 30, 2015 at 11:38 AM 0
Share

Passing a gameobject is fine (look at the overload at the bottom of the Network.Destroy page), but as @DaveCarlile points out, the second parameter is just wrong.

avatar image PogyManTV · Jun 30, 2015 at 12:45 PM 0
Share

Ok guys thank you all for answers but iam stupid i have no idea what are you telling me to do with that script i know the simple scripting in the monodevelop but when it comes to network i have no clue :/ so here is again my script and please can somebody check that script and fix what is wrong with them ? I will be happy as hell because i just want to add the audio when player comes to the resource and take it

Script:

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class ItemPickup : $$anonymous$$onoBehaviour {

 public AudioClip pickupSound;
 public static void Destroy(GameObject gameObject);



 // Use this for initialization
 void Start () {
     StartCoroutine (DespawnTimer ());

 }
 
 // Update is called once per frame
 void Update () {
 
 }

 void OnTriggerEnter(Collider other)
 {
     if(other.tag == "Player")
     {
         if(gameObject.tag == "Item")
         {
             Inventory inventory = GameObject.Find("Inventory").GetComponent<Inventory>();

             if(gameObject.name.Equals("Wood"))
             {
                 audio.PlayOneShot(pickupSound);    
                 Network.Destroy(gameObject,pickupSound.length);
                 inventory.AddItem("Wood");
             
             }
         }
     }
 }

 IEnumerator DespawnTimer()
 {
     yield return new WaitForSeconds (120);
     Network.Destroy(gameObject);
 }

}

avatar image Dave-Carlile · Jun 30, 2015 at 12:50 PM 0
Share

Remove this: public static void Destroy(GameObject gameObject);

Change this: Network.Destroy(gameObject,pickupSound.length);

To this: Network.Destroy(gameObject);

If you look at the Destroy call you have on line 39 you should be able to see the difference between that and the one on line 28.

Edit: I think I see where the confusion might lie. GameObject.Destroy does have an overload that accepts a delay parameter, but Network.Destroy doesn't have that option.

Good luck!

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

Csharp error - PLS help :( | error CS1501 1 Answer

Destroying a component over network? 1 Answer

No overload for method 'GetMethod' takes 5 argument 0 Answers

Alternative to RPC for destroying objects across a network 0 Answers

Couldn't destroy object because the associate network view was not found 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