What is wrong with this code?

#pragma strict
var other : GameObject;

function Update ()
{
function OnMouseDown()
{
other.GetComponent.().Play();
}
}

@Dog Gamer

Actually there are several problems with your script

  1. You can not place a function within a function
  2. other.GetComponent.() is incorrect it should be other.GetComponent()
  3. You need to pass a component type in to GetComponent like so other.GetComponent(SpriteRenderer)
  4. Most components do not have a Play() method so unless your component type is something like an animation our AudioSource you may want to use something else like enable = true;

Below is an example

#pragma strict
var other : GameObject; 

function OnMouseDown()
{
    if (other != null)
    {
        other.GetComponent(SpriteRenderer).enabled = true;
    }
}

You wrote:

other.GetComponent.().Play();

It actually is:

other.GetComponent().Play(); //Without the dot after "Component"

I hope this solves your problem :slight_smile: