Need Help with Pun Basic tutorial part 6 (Health)

Hello,
i started following the tutorial about PUN, and it was working fine since i come to part6 about the Health.
i wrote the entire script, it seams i didn't made any syntaxe error, but i get 2 error messages in the console:


Assets/_Scripts/PlayerManager.cs(73,20): error CS0120: An object reference is required to access non-static member `PhotonView.isMine'
Assets/_Scripts/PlayerManager.cs(97,20): error CS0120: An object reference is required to access non-static member `PhotonView.isMine'


and here is the code wich should be similar to the tutorial:

using UnityEngine;
using UnityEngine.EventSystems;
 
using System.Collections;
 
namespace ***.**************.**********
{
    /// <summary>
    /// Player manager. 
    /// Handles fire Input and Beams.
    /// </summary>
    public class PlayerManager : Photon.PunBehaviour 
	{
 
        #region Public Variables
 
        [Tooltip("The Beams GameObject to control")]
        public GameObject Beams;
		[Tooltip("The current Health of the player")]
		public float Health = 1f;
 
        #endregion
 
        #region Private Variables
 
        //True, when the user is firing
        bool IsFiring;
 
        #endregion
 
        #region MonoBehaviour CallBacks
 
        /// <summary>
        /// MonoBehaviour method called on GameObject by Unity during early initialization phase.
        /// </summary>
        public void Awake()
        {
            if (Beams==null)
            {
                Debug.LogError("<Color=Red><a>Missing</a></Color> Beams Reference.",this);
            }else{
                Beams.SetActive(false);
            }
 
        }
 
        /// <summary>
        /// MonoBehaviour method called on GameObject by Unity on every frame.
        /// </summary>
        public void Update()
        {
            ProcessInputs ();
			if (Health <= 0f)
			{
				GameManager.Instance.LeaveRoom();
			}

            // trigger Beams active state 
            if (Beams!=null && IsFiring != Beams.GetActive ()) {
                Beams.SetActive(IsFiring);
            }

        }
		
		///<Summary>
		///MonoBehaviour called when the collider 'other' enters the trigger.
		/// Affect Health of th Player if the collider is a beam
		///Note: When jumping and firing at the same, you'll find that the player's own beam intersects with itself
		/// one could move the collider further away to prevent this check if the beam belongs to the player.
		///</Summary>

		public void OnTriggerEnter(Collider other)
		{
			if (!PhotonView.isMine)
			{
				return;
			}

			// we are only interested in Beamers
			//We should be using tags but for the sake of distribution, let's simply check by name.
			if (!other.name.Contains("Beam"))
			{
				return;
			}
				Health -= 0.1f;
			
		}

		/// <Summary>
		/// MonoBehaviour method called once per frame for every Collider 'other' that is touching the trigger.
		/// We're going to affect health while the beams are touching th player
		/// </Summary>
		/// <param name = "other"> Other.</param>

		public void OnTriggerStay(Collider other)
		{
			// We don't do anything if we are not the local player.
			if (!PhotonView.isMine)
			{
				return;
			}

			// we are only interested in Beamers
			// we should be using tags but for the sake of distribution, let's simply check by name.
			if (!other.name.Contains("Beam"))
			{
				return;
			}
			Health -= 0.1f*Time.deltaTime;
		}
        #endregion
 
        #region Custom
 
        /// <summary>
        /// Processes the inputs. Maintain a flag representing when the user is pressing Fire.
        /// </summary>
        void ProcessInputs()
        {
 
            if (Input.GetButtonDown ("Fire1") ) {
                if (!IsFiring)
                {
                    IsFiring = true;
                }
            }
 
            if (Input.GetButtonUp ("Fire1") ) {
                if (IsFiring)
                {
                    IsFiring = false;
                }
            }
        }
        #endregion
 
    }
}

Comments

  • Hi @BlackantMaster,

    as far as I can tell you are missing an object reference to the PhotonView component. Please add private PhotonView photonView; to the PlayerManager class and photonView = GetComponent<PhotonView>(); to its Awake function. Please also mind the uppercase 'P' for the class name and the lowercase 'p' for the variable name.
  • ha my god you got it !!
    it was a P instead of a p !!

    congrats and thanks a lot !