Marco Polo Clone using EasyTouch Joystick issue

Options
​Hello,

I'm using Unity 4.6.0 and I deploy to iOS. Working on a Macbook Pro.

I modified the Marco Polo tut and everything seems to work fine except for enabling the camera and controls for the player.

The tut here: http://doc.exitgames.com/en/pun/current ... marco-polo

recommend grabbing the camera and player controls and enabling them to eliminate both players being controlled by one joystick.

The issue is that I use EasyTouch (EasyJoystick portion) for controls but I simply cannot get access to the "FlyJoystick" nor the camera which is all part of the player prefab I instantiate.

I get a NullReference error at lines marked in the code.
using UnityEngine;

public class PigRandomMatchmaker : Photon.MonoBehaviour
{
	private PhotonView myPhotonView;
	
	// Use this for initialization
	void Start()
	{
		        PhotonNetwork.ConnectUsingSettings("0.1");
	}
	
	void OnJoinedLobby()
	{
		         Debug.Log("JoinRandom");
		         PhotonNetwork.JoinRandomRoom();
	}
	
	void OnPhotonRandomJoinFailed()
	{
		          PhotonNetwork.CreateRoom(null);
	}

	void OnJoinedRoom()
	{
          float spawnPositionX = 283.0f;
          float spawnPositionY = 500.0f;
          float spawnPositionZ = 1325.0f;
		
         GameObject player = PhotonNetwork.Instantiate("PigPrefab", new     
             Vector3(spawnPositionX,spawnPositionY,spawnPositionZ), Quaternion.identity, 0);


	    EasyJoystick FlyJoystick = player.GetComponent("FlyJoystick") as EasyJoystick;
error->  FlyJoystick.enabled = true;

            Camera camera = GetComponent("MainCam") as Camera;
 error>  camera.enabled = true;

		
             myPhotonView = player.GetComponent<PhotonView>();
	}

	void OnGUI()
	{
	        GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
		
  		if (PhotonNetwork.connectionStateDetailed == PeerState.Joined)
		{
   			bool shoutMarco = GameLogic.playerWhoIsIt == PhotonNetwork.player.ID;
			
 			if (shoutMarco && GUILayout.Button("Marco!"))
 			{
				myPhotonView.RPC("Marco", PhotonTargets.All);
 			}
			if (!shoutMarco && GUILayout.Button("Polo!"))
			 {
 				myPhotonView.RPC("Polo", PhotonTargets.All);
			 }
		}
	}
}


NullReferenceException: Object reference not set to an instance of an object

Anyone ever use Easytouch successfully with PUN+?

Thanks!

Comments

  • vadim
    Options
    Hi,

    You need to attach component with name "FlyJoystick" (via 'Add Component' button in prefab inspector, for instance) to be able retrieve it with GetComponent call.
  • FGStud
    Options
    Hi,

    Thanks for getting back to me so fast.

    I do have the "FlyJoystick" and Camera in the prefab. The project I sent via email should show that.

    I have attached some images of screenshots also.

    [img][/img]http://i58.tinypic.com/2weypol.jpg


    [img][/img]http://i57.tinypic.com/ndwtcj.jpg



    I'm thinking I may need to put a delay before trying to access joystick and camera perhaps?

    If there is any other info you need let me know.

    Cheers!

    EDIT: I just tried a delay with this code but it still claims null.
    void OnJoinedRoom()
    	{
    		float spawnPositionX = 283.0f;
    		float spawnPositionY = 500.0f;
    		float spawnPositionZ = 1325.0f;
    		
    	player = PhotonNetwork.Instantiate("PigPrefab", new Vector3(spawnPositionX,spawnPositionY,spawnPositionZ), Quaternion.identity, 0);
    
    	StartCoroutine(	"ShowControlsAndCamera");
    }
    
    IEnumerator ShowControlsAndCamera ()
    	{
    		yield return new WaitForSeconds (10);
    
    		print (Time.time);
    
    		EasyJoystick FlyJoystick = player.GetComponent("FlyJoystick") as EasyJoystick;
    error>	FlyJoystick.enabled = true;
    
    		Camera Mycamera = GetComponent("MainCam") as Camera;
    		Mycamera.enabled = true;
    
    		myPhotonView = player.GetComponent<PhotonView>();
    
    	}
    
    

    If you need me to attach the project I can ...

    I just added another screenshot. Is it an issue that the Observed Component "PigPrefab (Transform)" as opposed to the demo which shows the Observed Component to be "monsterprefab (NetworkCharacter)" ? One is a "NetworkCharacter" and mine is a "Transform"

    http://i60.tinypic.com/2r7vy3m.jpg
  • FGStud
    Options
    Still banging my head on this. I'm guessing it has something to do with my prefab not being a "NetworkCharacter"?

    Any clues why my prefab would show as a "Transform" as Observed Component whereas in the Marco Polo Demo the player prefab shows as a "NetworkCharacter"?

    If anyone needs to see the full project to see what I mean it's located here:

    https://drive.google.com/file/d/0B2qs8g ... sp=sharing
  • vadim
    Options
    About screenshots.
    I see FlyJoystick item in PigPrefab hierarchy but not in PigPrefab components.
    Can you please select PigPrefab object and add FlyJoystick component with 'Add Component' button at bottom of components list as I wrote you before?
  • FGStud
    Options
    Hi vadim,

    Sorry I should have mentioned that I did try that but still got the null ref error.

    I have been able to modify the Kyle robot demo to work with my character, EasyJoystic and mobile deployment. So far it all seems to be working ok.

    I see a good bit of stutter in the anims. What would you recommend to help the animation stutter?

    Would a dedicated server help or is this an issue of cellular connection or perhaps model/anim complexity?

    Again sorry for not updating my progress here.
  • vadim
    Options
    Nice to hear that you get that joystick working.
    Are animation problems network related? Do you sync them somehow and they switched abruptly producing these stutter or what?
  • FGStud
    Options
    I think I narrowed my problem down so I deleted the verbose stuff that was below.

    Here is the issue I believe. See the pic attached. Why is my observed component NOT a "Photon TransformView" (like the Kyle is)? Mine just keeps showing it as a "Transform".

    jaxf6w.jpg

    UPDATE: I just tried rebuilding my prefab and I still see the observed component as a "Transform" and not a "Photon TransformView" ... any ideas?