- Home /
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 ://
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.
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 :/
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.
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.
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);
}
}
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!
Your answer
Follow this Question
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