есть скрипт 1
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerShoot : NetworkBehaviour {
public Weapon weapon;/*dalee ssylaysa na weaponchange*/
public Camera CameraTR;
private RaycastHit hit;
private Ray ray;
public string str;
void Update ()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Shoot ();
}
}
void Shoot()
{
ray = CameraTR.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast(ray,out hit, weapon.range))
{
if (hit.transform.tag == "Player") {
string id = hit.transform.name;
Cmdshoot (id, weapon.damage);
}
else if (hit.transform.tag == "destroyable")
{
string id = hit.transform.name;
Cmddestroy (id);
Debug.Log ("wwwwwww");
}
}
}
[Command]
void Cmdshoot (string Id,int dmg)
{
GameObject go = GameObject.Find (Id);
go.GetComponent<PlayerInfo> ().GetDamage (dmg);
}
[Command]
void Cmddestroy (string ID)
{
GameObject go = GameObject.Find (ID);
go.GetComponent<destroycube> ().f = true;
Debug.Log ("dddddddd");
GetComponent<SyncCube> ().ch -= 1;
}
}
и скрипт 2
using System.Collections;
using UnityEngine.Networking;
using UnityEngine;
public class destroycube : NetworkBehaviour {
public bool f;
// Use this for initialization
void Start () {
f = false;
}
void Update () {
if (f)
{
Destroy (this.gameObject);
}
}
}
в первом скрипте в строке go.GetComponent<destroycube> ().f = true;
выпадает ошибка 'NullReferenceException' при попытке клиента удалить объект.
Подскажите, пожалуйста, как исправить?
GameObject go = GameObject.Find (ID);не нашла с такимIDничего, потому, видимо,go == null. Это же нужно заниматься отладкой: ставить точку останова на эту строку и проверять значениеIDиgoпри след.шаге. – Bulson Jan 25 '18 at 10:42