K
K
Kot Kotov2020-05-17 14:01:19
C++ / C#
Kot Kotov, 2020-05-17 14:01:19

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);

it's on the bullet
public void UpSpeed(Transform gunPoint, int speed)
    {
      rb.AddForce(gunPoint.up*speed, ForceMode2D.Impulse);
    }

And on startup I get this error:
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)

If I'm not mistaken, the problem is not the correct type of the bullet variable, because before adding a photon everything worked.
I will be grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kot Kotov, 2020-05-17
@kot123123

Hello, I found the problem! I confused the initialization method from c # with c and instead of start I wrote setup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question