Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Click a 3d cube works only sometimes...

Discussion in 'Getting Started' started by sefiroths, May 23, 2016.

  1. sefiroths

    sefiroths

    Joined:
    Dec 13, 2014
    Posts:
    24
    Hi, I have a 3d cube in prefabs.
    I istanziate this cubes in Start() of a gameobject named init_playground:
    Code (CSharp):
    1. caselle=newGameObject[9][];
    2. for(intr=0;r<9;r++){
    3. caselle[r]=newGameObject[9];
    4. for(intc=0;c<9;c++){
    5. caselle[r][c]=(GameObject)Instantiate(casella,newVector3((c-4)*offset,-1,(4-r)*offset),Quaternion.identity);
    6. caselle[r][c].GetComponent<CasellaSelect>().riga=r;
    7. caselle[r][c].GetComponent<CasellaSelect>().colonna=c;
    8. in the cube I have a script "CasellaSelect" to detect touch:
    9. [code=CSharp]using UnityEngine;
    10. using System.Collections;
    11.  
    12. public class CasellaSelect : MonoBehaviour {
    13.     public int riga,colonna;
    14.     public void eventOnMouseDown(){
    15.         Debug.Log ("cliccato r:"+riga+" c:"+colonna);
    16.     }
    17. }
    18.  
    The script sometimes not trigger the event...
    I attach the cube prefab.
    Why sometimes the event is triggered, sometimes not?

    EDIT: I have notices that only clicks that are in the upper area to the center of the screen are not triggered

    thanks
     

    Attached Files:

  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    The code you posted won't compile, but probably because your sharing two snippets in one block. Maybe share the whole script(s) in its original format, with commenting using "// this does..." or "/* another comment */" so others can easily copy paste your code into an ide and look at it for errors.
     
  3. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    Try changing eventOnMouseDown to OnMouseDown.

    I made that change, and it seems to work fine for me.
     
    MrUnecht likes this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Select your event system then hover over the scene. The event system will show you what it thinks you are hovering over.
     
    JoeStrout likes this.
  5. sefiroths

    sefiroths

    Joined:
    Dec 13, 2014
    Posts:
    24