How to specifie a GameObject from the Hierarchie

So Ive got two spotlights and theire oposite to each other (Sun and moon) and I dont want to make a script for both of them…
Im a newbie and i know the basic of C# because it looks like java(not javascript, Java) and heres the code i tried I KNOW ITS TOTALLY WRONG… and it doesnt make any sense to you is just a way to explain miself

if (GameObject.name(“sol”) == true){
if (transform.rotation == new Vector3(90,0,0)){
string sol = “Meio Dia”;
}
}

So here you have the code thats just a wrap and yeah thanks for your time (Now its mine XD)

If I understand, you might want to do this.

Basically, you want to add the tag “Sun” to your Sun object. This will allow you to find that object and do functions on and with it.

Also, rotations are not in Vector3. They are Quaternions. So try this piece of code out.

public GameObject sun;

void Start(){
     sun= GameObject.FindGameObjectWithTag ("Sun");
}

//Personally I wouldn't check this in Update but it really depends on what you need.
void Update(){
   Quaternion check = new Quaternion(90,0,0,1);
   if(sun.transform.rotation == check){
          sol = "Meio Dia";
}
}