- Home /
Photonview "this" does not exist in current context
I'm new to Photon and I have tried searching for answers everywhere but could not find any So I have this error on this line of code Error:Keyword this' is not available in the current context Here is the line that has the error
PhotonView photonView = PhotonView.Get(this);`
Here is the entire script`using UnityEngine; using System.Collections;
/// /// This script is attached to the player and it /// ensures that every players position, rotation, and scale, /// are kept up to date across the network. /// /// This script is closely based on a script written by M2H. ///
public class MovementUpdate : MonoBehaviour {
//Variables Start___________________________________
private Vector3 lastPosition;
private Quaternion lastRotation;
private Transform myTransform;
PhotonView photonView = PhotonView.Get(this);
//variables End
// Use this for initialization
void Start ()
{
if(photonView.isMine == true)
{
myTransform = transform;
//Ensure that everyone sees the player at the correct location
//the moment they spawn.
photonView.RPC("updateMovement", PhotonTargets.OthersBuffered,
myTransform.position, myTransform.rotation);
}
else
{
enabled = false;
}
}
// Update is called once per frame
void Update ()
{
//If the player has moved at all then fire off an RPC to update the players
//position and rotation across the network.
if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1)
{
//Capture the player's position before the RPC is fired off and use this
//to determine if the player has moved in the if statement above.
lastPosition = myTransform.position;
photonView.RPC("updateMovement", PhotonTargets.OthersBuffered,
myTransform.position, myTransform.rotation);
}
if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
{
//Capture the player's rotation before the RPC is fired off and use this
//to determine if the player has turned in the if statement above.
lastRotation = myTransform.rotation;
photonView.RPC("updateMovement", PhotonTargets.OthersBuffered,
myTransform.position, myTransform.rotation);
}
}
[RPC]
void updateMovement (Vector3 newPosition, Quaternion newRotation)
{
transform.position = newPosition;
transform.rotation = newRotation;
}
} `
I am not too sure but ins$$anonymous$$d of:
public class $$anonymous$$ovementUpdate : $$anonymous$$onoBehaviour
try:
public class $$anonymous$$ovementUpdate : Photon.$$anonymous$$onoBehaviour
Pretty sure you cannot use any of the PhotonView's functionality without it.
Please format your code. If you don't know how, watch the tutorial video on the right
Answer by octav88 · Mar 29, 2021 at 12:19 PM
Using this one works for me:
MyClass: MonoBehaviourPunCallbacks
Your answer
Follow this Question
Related Questions
Photon/Network - Killing A Client Enemy Unit 3 Answers
Send gameobject through photon RPC 1 Answer
Experience going to both players, Photon Unity Networking 0 Answers
Synchronize array with simultaneous access via Photon Network RPC 1 Answer
Syncing FPS Firing Sound over network via RPC {PHOTON} 1 Answer