title: Unity c# how to properly use GetComponent
body: <p>I am in no way a coding novice but I just picked up unity and I'm trying &quot;get it&quot;</p>
  <p>My question involves this code. it is not part of an active project. it is simply an attempt to understand the system</p>
  <pre><code>private SpriteRenderer beans2;
  
  public Sprite beanimmage;
  // Start is called before the first frame update
  void Start()
  {
  beans2 = gameObject.GetComponent&lt;SpriteRenderer&gt;();   
  
  beans2.sprite = beanimmage;
  }
  </code></pre>
  <p>from what I understand this code allows me to manipulate the SpriteRenderer of the game object this code is attached to by assigning it to beans2 and then changing the Sprite of beans2 to beanimmage and works fine in the system</p>
  <p>My question is -<br />
  Is their a way to assign beans2 to the spriterenderer of a diffident game object? The object i have this code attached to is just a game object called test is their a way to assign the beans2 variable to the SpriteRenderer of my test2 object instead ?</p>
  <p>something like this ?</p>
  <pre><code>beans2 = test2.gameObject.GetComponent&lt;SpriteRenderer&gt;();
  beans2 = gameObject.test2.GetComponent&lt;SpriteRenderer&gt;();
  </code></pre>