Accessing variables with GetComponent?

Can I access two variables with get component, when I only assign 1 variable? That sounds confusing, but see the code it will make sense:

    var otherScript  = GameObject.Find("SkeletonDamageWGR");
	// Stop Damage when Shield Bashed
	if (other.gameObject.tag == "Shield")
	{
	otherScript.GetComponent(WarriorDmgGreen).StopInvokeDmg();
	otherScript.GetComponent(WarriorDmgGreen).ToggleSD();
	}
	
OR

    var otherScript  = GameObject.Find("SkeletonDamageWGR");
	var otherScript2 = GameObject.Find("SkeletonDamageWGR");
	// Stop Damage when Shield Bashed
	if (other.gameObject.tag == "Shield")
	{
	otherScript.GetComponent(WarriorDmgGreen).StopInvokeDmg();
	otherScript2.GetComponent(WarriorDmgGreen).ToggleSD();
	}

It should be:

var otherScript = GameObject.Find("SkeletonDamageWGR").GetComponent(WarriorDmgGreen);

if (other.CompareTag("Shield")) {
    otherScript.StopInvokeDmg();
    otherScript.ToggleSD();
}

–Eric

Oh ok, thank you. Would the other way give an error? Specifically the first example? Because it was running fine, but when I play my game through xcode im getting an error from that function.

It wouldn’t produce an error (unless there’s no object by that name and you get a null reference exception), but it would be less efficient.

–Eric

Ok thank you.