Search Unity

Resolved OnMouseDown does not work while camera is moving

Discussion in 'Scripting' started by khrysller, May 14, 2020.

  1. khrysller

    khrysller

    Joined:
    Mar 14, 2019
    Posts:
    125
    Hi. I have this code and it works. I have a camera that follows the player, and if I try to click on the object while the camera is moving it seens that the click is not working

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CollectRainballs : MonoBehaviour
    6. {
    7.     public GameObject Rainball;
    8.  
    9.     void OnMouseDown()
    10.     {
    11.         Destroy(Rainball);
    12.     }
    13. }
    Am I missing something? Thanks
     
    Last edited: May 14, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Which GameObject is this CollectRainballs script attached to? Is it attached to the rainball itself? Is Rainball a reference to this component's own GameObject?
     
    Joe-Censored likes this.
  3. khrysller

    khrysller

    Joined:
    Mar 14, 2019
    Posts:
    125
    Sorry for not giving that information on the start. Yes, the script is attached to the object itself and I added the object on the inspector... it works if I do not move the character (which has a camera follow script to it) and this camera move is dening the click... as I see.