I’ve used photon rpc to send variables over the photon network. But I’ve got this error: NullReferenceException: Object reference not set to an instance of an object add_point.Update () (at Assets/add_point.cs:46)
The problem is. If I score(I have tried it in all the goals) then is the score 0.
This is my codes:
code1:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
using Photon;
public class add_point : PunBehaviour {
public Text Scoreteam1;
public Text Scoreteam2;
public float score_team1 = 0;
public float score_team2 = 0;
public float waittime = 2;
public float step = 0.1f;
public int mouseposition;
PhotonView pv;
public void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "goalcube1") {
transform.position = GameObject.Find ("ballposition").transform.position;
this.gameObject.GetComponent<Rigidbody> ().velocity = Vector3.zero;
score_team1 += 1;
}
if (other.gameObject.tag == "goalcube2"){
transform.position = GameObject.Find("ballposition").transform.position;
score_team2 += 1;
this.gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
public void Start(){
Scoreteam1 = GameObject.Find ("score team 1").GetComponent<Text> ();
Scoreteam2 = GameObject.Find ("score team 2").GetComponent<Text> ();
pv = GameObject.Find ("BlueSuitFree01(Clone)").GetComponent<PhotonView> ();
}
public void Update ()
{
Debug.Log (score_team1);
pv.RPC ("team1", PhotonTargets.AllBuffered,"score_team1");
if (Input.GetKeyDown (KeyCode.R)) {
score_team1 = 0;
score_team2 = 0;
}
if (Input.GetButtonDown("Fire1")){
score_team1 = 0;
score_team2 = 0;
}
if (CrossPlatformInputManager.GetButtonDown("JumpButton")){
score_team1=0;
score_team2=0;
}
}
}
`
Code2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text;
using UnityEngine;
using Photon;
public class rpc : PunBehaviour {
public Text scoreteam1;
void Start () {
Debug.Log (GameObject.Find ("score team 1"));
scoreteam1 = GameObject.Find ("score team 1").GetComponent<Text> ();
}
// Update is called once per frame
[PunRPC]
public void team1 (float score_team1)
{
Debug.Log ("score_team1");
scoreteam1.text = score_team1.ToString ();
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
Debug.Log ("Now sending");
}
else
{
}
}
}