Answer the question
In order to leave comments, you need to log in
How can I fix my mistake when calling a function on an object via pun2?
I decided to try to figure out the multiplayer for unity. I used photon 2. BUT then I ran into a problem, this construction does not work:
this is the code on the player
GameObject clone = PhotonNetwork.Instantiate(bullet.name, gunPoint.position, gunPoint.rotation); clone.gameObject.GetComponent<Bullet>().UpSpeed(gunPoint,speed);
public void UpSpeed(Transform gunPoint, int speed)
{
rb.AddForce(gunPoint.up*speed, ForceMode2D.Impulse);
}
NullReferenceException: Object reference not set to an instance of an object
Bullet.UpSpeed (UnityEngine.Transform gunPoint, System.Int32 speed) (at Assets/Scripts/Bullet.cs:16)
PlayerMidle.Fire (System.Boolean SB) (at Assets/Scripts/PlayerMidle.cs:84)
PlayerMidle.Update () (at Assets/Scripts/PlayerMidle.cs:70)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question