简体   繁体   中英

unity photon networking mousedown function not working (beginner)

i am new to photon and I am trying to detect when the mouse is clicked to simulate recoil and send a raycast. After I noticed it wasnt working, I used a debug function to see if the onmousedown function was working but it did not here is the code for my player

void OnMouseDown()
    {
        Debug.Log("mousedown");
        if (photonView.IsMine)
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.transform.position, Camera.transform.forward, out hit))
            {
                UnityEngine.Debug.Log(hit.transform.name);

            }
        }

since you are raycadting anyways, I would reccomend using the bool variable: Input.GetKeyDown or Input.GetKey.

void Update()
{
  if (Input.GetKeyDown(KeyCode.Mouse0)
  {
    //Do your thing like raycast
  }
}

If you really want to use OnMouseDown, try this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM