photonView.RequestOwnership(); it does not work

I'm creating a multiplayer game and I would like to insert the grab system, I know I have to put photonView.RequestOwnership ();
but I do it, it does not give me error, only when I take the object does not make me take, instead if I do not put photonView.RequestOwnership(); it works great, how do I solve it?

on photonview I already put on "TakeOver"

here are the codes of the files

GrabObjects.cs

photonView.RequestOwnership(); I put it inside the function, so it's okay? do you do it well?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

[RequireComponent(typeof (PhotonView))]
public class GrabObjects : Photon.MonoBehaviour
{
 	
	
	public float grabPower = 10.0f; 
	public float throwPower = 25.0f;
	public float RayDistance = 3.0f;
	public LayerMask layerMask;
	private bool grab, drop = false;

	public Transform pos;
	public float adjust;
	Rigidbody obj;

	void Update()
	{ 

		if (Input.GetKeyDown(KeyCode.Mouse1))
		{
			RaycastHit hit;
			if(Physics.Raycast(transform.position, transform.forward, out hit, RayDistance, layerMask.value))
			{
				Pickable pickable = hit.collider.GetComponent<Pickable>();
				if(pickable)
				{
                                        <b class="Bold">photonView.RequestOwnership();</b>
					grab = true;
					obj = hit.rigidbody;
					obj.isKinematic = true;
					obj.GetComponent<Collider>().enabled = false;
					obj.transform.parent = pos;
				}		
			}
		}	
		
		if (Input.GetKeyUp(KeyCode.Mouse1))
		{ 
			if(grab)
			{
				StartCoroutine(PrepareToDrop(3f));
			}	
		}
		
		if (Input.GetKeyDown(KeyCode.Mouse0))
		{ 
			if(grab)
			{
				StartCoroutine(PrepareToDrop(throwPower));
			}	
		}

		if(grab)
		{	
			obj.transform.position = Vector3.Lerp(obj.transform.position, pos.position + (pos.transform.forward * adjust) - (pos.transform.up * 0.4f), Time.deltaTime * grabPower); 
			obj.transform.rotation = Quaternion.Lerp(obj.transform.rotation, pos.rotation, Time.deltaTime * 5f);
		}
	} 

	IEnumerator PrepareToDrop(float power)
	{
		RaycastHit hits;
		while(!drop)
		{
			if(Physics.Raycast(transform.position, transform.forward, out hits, 1.5f, layerMask.value)) 
				drop = false;
			else 
				drop = true;
			yield return null;
		}
		
		obj.transform.parent = null;
		obj.isKinematic = false;
		obj.GetComponent<Collider>().enabled = true;
		obj.velocity = transform.forward * power;
		drop = grab = false;
	}
	}


Here is the other, this is empty is placed in the object reference point to make the script understand to take that object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof (PhotonView))]
public class Pickable : Photon.MonoBehaviour {
	
}

Comments

  • That is too vague to answer.
    Keep in mind that very few developers here will have the time to run your code and figure out what you intend to do.
  • Tobias said:

    That is too vague to answer.
    Keep in mind that very few developers here will have the time to run your code and figure out what you intend to do.

    thanks you I would like to change the discussion but I do not know how to do it, so I leave the code here of the part that interests me

    if (Input.GetKeyDown(KeyCode.Mouse1))
    {
    RaycastHit hit;
    if(Physics.Raycast(transform.position, transform.forward, out hit, RayDistance, layerMask.value))
    {
    Pickable pickable = hit.collider.GetComponent();
    if(pickable)
    {
    photonView.RequestOwnership();
    grab = true;
    obj = hit.rigidbody;
    obj.isKinematic = true;
    obj.GetComponent().enabled = false;
    obj.transform.parent = pos;
    }
    }
    }