- Home /
Question by
lonelycamper · Jul 07, 2017 at 04:54 AM ·
networkingmultiplayerfunctionsfunction call
NullReferenceException UnityEngine.Component.GetComponent[NetworkIdentity] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ComponentBindings.gen.cs:48)
Problem with calling a function from other scripts, Thanks.
Script A:
Script B Name = new Script B();
if (Physics.Raycast(ray, out hitInfo, weaponRange, mask))
{
Instantiate(impactEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
if (hitInfo.collider.tag == "Player")
{
//other.CmdPlayerShot(hitInfo.collider.name);
Name.CmdPlayerShot(hitInfo.collider.name);
//Destroy(hitInfo.transform.gameObject);
return;
}
Script B:
[Command]
public void CmdPlayerShot(string _playerID)
{
Debug.Log(_playerID + "has been shot");
}
}
Comment
Wouldn't work since Another script is a type
Best Answer
Answer by vir1234 · Jul 07, 2017 at 05:03 AM
attach network identity to the gameobject
i think you also have to attach network identity to the game object where script a is attached
Yeah it has one i'm checking something I might have messed my prefabs up by accident and added the wrong script lemme check
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Networking Camera not attaching to instantiated object 2 Answers
Multiplayer Client Missing Reference To Spawn Object 1 Answer
Animation over network using rpcs 0 Answers