I have a script that instantiates fireballs into the game and a script that updates the fireballs, The fireballs are killed fine if they are left to die from there lifespan reaching 0. However if the trigger method is called the fireball is not killed instantly and dies after its lifespan reaches 0 with an error: Could’nt perform remote Network.Destroy because the netwrok view 'ID here" could not be located.
Here is how the fireball is instantiated:
using UnityEngine;
using System.Collections;
public class Mage : MonoBehaviour {
public GameObject fireball;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
Network.Instantiate(fireball, transform.position + transform.forward, transform.rotation, 0);
}
}
}
and here is how they are updated
using UnityEngine;
using System.Collections;
public class Fireball : MonoBehaviour {
private float moveSpeed = 15f;
private Transform myTransform;
private float lifespan;
private int damage;
private PlayerScript PS;
void Awake()
{
myTransform = transform;
}
// Use this for initialization
void Start () {
damage = -21;
lifespan = 10f;
}
// Update is called once per frame
void Update () {
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
lifespan -= Time.deltaTime;
if(lifespan < 0)
{
Network.Destroy(this.gameObject);
Destroy(this.gameObject);
}
}
void OnTriggerEnter(Collider other)
{
//PS = other.gameObject.GetComponent<PlayerScript>();
//PS.AdjustCurHealth(damage);
networkView.RPC("Kill", RPCMode.All);
}
[RPC]
void Kill()
{
Network.Destroy(this.gameObject);
}
}
Does anyone know what the problem is and why it only occurs if the fireball has collided?
Haven’t really worked with the Network or C#,but I’m kinda having a hard time understanding why you have two methods (or functions or whatever they were called in C#) for the destruction of the object.I mean the following:
Your right I could (and should). I only put the RPC call in there for debugging purposes however I have fixed this issue by adding a rigidbody to my fireball.