0

basically, I am trying to display input of inputfield on the instantiated photon object using photon.rpc . However, input of inputfield does not even write anything on the console. Here is my solution

// ----------------------------------------------------------------------------
// <copyright file="CharacterInstantiation.cs" company="Exit Games GmbH">
// Photon Voice Demo for PUN- Copyright (C) 2016 Exit Games GmbH
// </copyright>
// <summary>
// Class that handles character instantiation when the actor is joined.
// It adds multiple prefabs support to OnJoinedInstantiate.
// </summary>
// <author>developer@photonengine.com</author>
// ----------------------------------------------------------------------------

namespace ExitGames.Demos.DemoPunVoice 
{
    using UnityEngine;

    public class CharacterInstantiation : OnJoinedInstantiate 
    {
        TextMesh output;
        PhotonView photonView;
        int i = 0;

        public delegate void OnCharacterInstantiated(GameObject character);

        public static event OnCharacterInstantiated CharacterInstantiated;

        public new void OnJoinedRoom() 
        {
            if (this.PrefabsToInstantiate != null) 
            {
                GameObject o = PrefabsToInstantiate[(PhotonNetwork.player.ID - 1) % 4];
                Debug.Log("Instantiating: " + o.name);
                Vector3 spawnPos = Vector3.zero;

                if (this.SpawnPosition != null) 
                {
                    spawnPos = this.SpawnPosition.position;
                }

                Vector3 random = Random.insideUnitSphere;
                random = this.PositionOffset * random.normalized;
                spawnPos += random;
                spawnPos.y = 0;
                Camera.main.transform.position += spawnPos;

                o = PhotonNetwork.Instantiate(o.name, spawnPos, Quaternion.identity, 0);

                if (CharacterInstantiated != null)
                {
                    CharacterInstantiated(o);
                }

                photonView = o.GetPhotonView();
            }
        }

        public void ReadStr(string s)
        {
            Debug.Log(s);
            Debug.Log("readStr" + s);
            photonView.RPC("ReadStringInput", PhotonTargets.All, s);
        }
    }
}

and i have a script under each prefab to be instantiated

using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;

public class ReadInput : MonoBehaviour
{
    private string input;

    TextMesh output;

    [PunRPC]
    public void ReadStringInput(string s)
    {
        Debug.Log(s);
        output = GetComponentInChildren<TextMesh>();
        output.text = s;
    }
}

There is no other error message and seems to properly call targeted function, but one problem is string input of the inputfield becomes null value, and it displays "" on the console on both functions. I correctly assigned ReadStr on "on End Edit" of inputfield, but it is very frustration that whatever input i put, it becomes a null value. I'd greatly appreciate if anyone helps me with this matter.

derHugo
  • 83,094
  • 9
  • 75
  • 115
W 3
  • 19
  • 2
  • instead of `OnEndEdit` rather try `OnSubmit` .. sounds to me like you are exiting the input field via `ESC` in which case it aborts the editing instead of submitting and applying the new text .. make sure to hit `ENTER` – derHugo Jan 10 '23 at 11:34

0 Answers0