Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

Need Help with Pun Basic tutorial part 6 (Health)

$
0
0
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 3 or 4 error message in the console:

i don't know if the first as anything to do whith the rest of the code it was not here before i start to write about health Management.
Request error (error): 
UnityEditor.AsyncHTTPClient:Done(State, Int32)

Assets/_Scripts/PlayerManager.cs(54,5): error CS0103: The name `GameManager' does not exist in the current context
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 ***.**************.**********
{
///
/// Player manager.
/// Handles fire Input and Beams.
///
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

///
/// MonoBehaviour method called on GameObject by Unity during early initialization phase.
///
public void Awake()
{
if (Beams==null)
{
Debug.LogError("Missing Beams Reference.",this);
}else{
Beams.SetActive(false);
}

}

///
/// MonoBehaviour method called on GameObject by Unity on every frame.
///
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.
///

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;

}

///
/// 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
///
/// Other.

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

///
/// Processes the inputs. Maintain a flag representing when the user is pressing Fire.
///
void ProcessInputs()
{

if (Input.GetButtonDown ("Fire1") ) {
if (!IsFiring)
{
IsFiring = true;
}
}

if (Input.GetButtonUp ("Fire1") ) {
if (IsFiring)
{
IsFiring = false;
}
}
}
#endregion

}
}

Viewing all articles
Browse latest Browse all 8947

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>