Really Bad Question I know - Pulling Functions in Classes

Options
Taurian
edited January 2012 in DotNet
Like most i'm fairly new to C#. But I have a simple problem. I just want to call a function in my PhotonServer.cs

The function looks like this:
public void SendEncryptedRequest(byte spaceOperationCode, byte spaceParameter, string spaceString, byte spaceChannel)
    {
        _peer.OpCustom(spaceOperationCode, new Dictionary<byte, object> {{ spaceParameter, spaceString }}, true,spaceChannel,true);
    }

In other CS File (MyPlayer.cs) i'm simply trying to call it. It's in a class of course.
using UnityEngine;
using System.Collections;
using ExitGames.Client.Photon;
using System.Collections.Generic;
using System;

private PhotonServer _photonServer;

	void OnGUI()
	{
		GUI.Box(new Rect(10,10,HealthBarLength,20),currentHealth + "/" + maxHealth);
		if (GUI.Button ( new Rect (10,40,100,20),"Simulate Hit"))
		{
			// Paramters are OpCode, Key, Data , ChannelID
			_photonServer = new PhotonServer();
			_photonServer.SendEncryptedRequest(101, 1, "-10", 0);

			//AdjustCurrentHealth(-10);
		}
	}

I know I need to assign what I want to do to an Object, then try to do what i'm doing. I just don't know how to do it in C#.

Thanks for the assist,

Comments

  • Tobias
    Options
    It doesn't look so bad. It would help if you let us know what the problem is you got. Look out for compiler errors in Unity (console)...
    You probably don't want to create a new PhotonServer every time that button is pressed. Instead, it should keep the state and connection and queue in operations like you do. So add a Awake() and create the new PhotonServer in there (just move the one line).