Search Unity

RightClick And LeftClick Event !

Discussion in 'Scripting' started by MR.Dawoodi, Dec 17, 2010.

  1. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    i have 2script for modify an object in game.
    One of the things I need to click on the left and one right-click on the put.
    one of scripts is C# and other is Java.
    i write script with java for this event , but one of script is java and i can't put C# script in Java.
    can i link C# script in Java ?
    and how can i write an script with java for this event's and link 2scripts at this ?

    thank's soooo much :D

    sry about my english :)
     
  2. Feyhu

    Feyhu

    Joined:
    Sep 14, 2010
    Posts:
    211
    what is the script? it is easy to convert c# to java or vice versa
     
  3. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    tnx carson:)

    how can i translate C# to Java ?
     
  4. Feyhu

    Feyhu

    Joined:
    Sep 14, 2010
    Posts:
    211
    mostly the variables are different.

    for example:

    c#:
    private bool notTrue = false;
    public int nine = 9;

    javascript:
    private var notTrue = false;
    public var nine = 9;
     
  5. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    i write this sample for here , plz see it and say to me problem's !
    with left and right click must change object material.but not work :( :confused:
    with no error.
    Code (csharp):
    1.  
    2. var materialA : Material;
    3. var materialB : Material;
    4. var materialC : Material;
    5. private var stause : int = 0;
    6. var e : Event = Event.current;
    7.  
    8. function OnMouseDown()
    9. {
    10.  
    11.     if(e.button == 0  e.isMouse)
    12.     {
    13.         if(stause == 0)
    14.         {
    15.             renderer.material = materialA;
    16.             stause = 1;
    17.         }
    18.         else
    19.         if(stause ==1)
    20.         {
    21.             renderer.material = materialB;
    22.             stause = 2;
    23.         }
    24.         else
    25.         if(stause ==2)
    26.         {
    27.             renderer.material = materialC;
    28.             stause = 0;
    29.         }
    30.     }
    31.     else
    32.     if(e.button == 1  e.isMouse)
    33.     {
    34.         if(stause == 0)
    35.         {
    36.             renderer.material = materialA;
    37.             stause = 1;
    38.         }
    39.         else
    40.         if(stause ==1)
    41.         {
    42.             renderer.material = materialB;
    43.             stause = 2;
    44.         }
    45.         else
    46.         if(stause ==2)
    47.         {
    48.             renderer.material = materialC;
    49.             stause = 0;
    50.         }
    51.     }
    52. }
    53.  
     
  6. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,572
    Try using
    if (Input.getMouseButtonDown(0)) {

    and
    if (Input.getMouseButtonDown(1)) {
     
  7. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    thank's.
    this might use at Function Update , but i use OnMouseDown !
     
  8. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    Who can help fix this code?