Disable click action when collision

I have a 2D block falling (like tetris) and is rotating when click on this. I would to disabled this action (rotation when click) when the blocks do collision with the ground. I try this but I don´t know why but it isn´t work. The rotation work but it doesn´t stop
This is the script to stop the rotation:

var rotar = rotaralclick;

function OnTriggerEnter(Otro : Collider)
{
    if (Otro.gameObject.name == "suelo") 
    {
        GetComponent.rotar.enabled=false;
    }
}

and this is the script of the rotation, in the same prefab

function Update ()
{
    if(Input.GetMouseButtonDown(0))
        transform.Rotate(0, 0, -90);
}

1 Answer

1

for your Bottom script, add the variable: var hasLanded = false;

this is what it should look like in the top Script:

 function OnTriggerEnter(Otro : Collider)
 {
     if (Otro.gameObject.name == "suelo") 
     {
         GetComponent.rotar.enabled=false;
        this.GetComponent( bottom Script name Goes here ).hasLanded = true;
     }
 }

and the bottom Script should look like this:

var hasLanded = false;

 function Update ()
 {
if(hasLanded == false)
{
     if(Input.GetMouseButtonDown(0))
         transform.Rotate(0, 0, -90);
 }
}

if i am reading what you’re saying, and both scripts are indeed on the same object, this will work.

hope this helps.

Thank ownerfate, the botton script work perfectly, but the second script didn´t work well, I change ontriggerenter and I wrote Oncollisionenter2D and it´s fine. Probably it was only a problem of my scene.