photonView.IsMine
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
photonView.IsMine
Persian99
2019-12-12 00:15:03
Hi there,
I feel kinda dumb asking this but I think that "photonView.IsMine" is not working, at least is not working on my project. I'm following step by step the tutorial from the documentation and I got stuck in this part when you check the others beams and check the player health. When I get to add it into OnTriggerEnter and OnTriggerStay method I get an error, it shows like if I wrote it wrong. I've been looking at the whole script for two hours and I can't find what's wrong.
I would really appreciate it if you could help me.
Here's a link to a screenshot I took from the script (I couldn't figure out how to upload a picture here so I uploaded to Google Drive):
https://drive.google.com/open?id=1JXYEKxstXN2HkxptSvGKr2m03sXTM2_j
Also, I'll leave de PlayerManager script I have:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
namespace Com.JmJdProd.Murderer
{
public class PlayerManager : MonoBehaviour
{
#region Private Fields
[Tooltip("The Beams GameObject to control")]
[SerializeField]
private GameObject beams;
//True, when the user is firing
bool IsFiring;
#endregion
#region Public Fields
[Tooltip("The current Health of our player")]
public float Health = 1f;
#endregion
#region MonoBehaviour CallBacks
/// <summary>
/// MonoBehaviour method called on GameObject by Unity during early initialization phase.
/// </summary>
void Awake()
{
if (beams == null)
{
Debug.LogError("<Color=Red><a>Missing</a></Color> Beams Reference.", this);
}
else
{
beams.SetActive(false);
}
}
void OnTriggerEnter(Collider other)
{
<b class="Bold"> if (PhotonView.IsMine)
{
return;
}</b>
if (!other.name.Contains("Beam"))
{
return;
}
Health -= 0.1f;
}
void OnTriggerStay(Collider other)
{
<b class="Bold"> if (!photonView.IsMine)
{
return;
}</b>
if (!other.name.Contains("Beam"))
{
return;
}
Health -= 0.1f * Time.deltaTime;
}
void Update()
{
if (Health <= 0f)
{
GameManager.Instance.LeaveRoom();
}
ProcessInputs();
// trigger Beams active state
if (beams != null && IsFiring != beams.activeInHierarchy)
{
beams.SetActive(IsFiring);
}
}
#endregion
#region Custom
void ProcessInputs()
{
if (Input.GetButtonDown("Fire1"))
{
if (!IsFiring)
{
IsFiring = true;
}
}
if (Input.GetButtonUp("Fire1"))
{
if (IsFiring)
{
IsFiring = false;
}
}
}
#endregion
}
}
Comments
I have the same issue. People have been asking about this over and over. Could someone address it?
This question has been answered, but for whatever reason, they don't update the tutorial. Remove the check for photonview.ismine and just ProcessInputs(); You will add the check in the next section properly.
Hi @Persian99, @jwehr,
Thank you for choosing Photon!
Documentation page update done.
Sorry for the inconvenience.
Thanks you for your patience and understanding.
@JohnTube and @jwehr
Thanks for answering, I just realized I missed something really important in the script ( 'MonoBehaviourPunCallBacks)
Anyway, I really appreciate you took your time to answer.
Thanks again and hope you have happy holidays.
Back to top