- Home /
Question by
Javimillan · May 20, 2017 at 08:49 AM ·
collisionnetworkingcolliderplayerscript.
Help with getting script of another player
Hi all,
I'm doing a multiplayer game, i have a prefab (players) with scripts and when two players collide i want to access to his script for get a variable. The problem is when i try to get his script with getComponent, i get the error "null reference not set to an instance of an object ". Why i cant access to other script and i get null? There is the code.
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Player")
{
if (id > other.gameObject.GetComponent<MovementMulti>().id) // <-- here get the NULL EXCEPTION
{
float aux = vZ;
float aux2 = vX;
vZ = other.gameObject.GetComponent<MovementMulti>().vZ;
vX = other.gameObject.GetComponent<MovementMulti>().vX;
other.gameObject.GetComponent<MovementMulti>().vZ = aux;
other.gameObject.GetComponent<MovementMulti>().vX = aux2;
}
}
}
Thanks.
Comment
Your answer
Follow this Question
Related Questions
Decreasing Player Health On Collision with Enemy 2 Answers
Auto-Scrolling Level - crushing player results in death 0 Answers
Script not recognizing collision 3 Answers
Lose health on collision 1 Answer
Parent Object 0 Answers