Object Rotation using a Slider

Good evening,

Sorry if this has been posted somewhere else… I have looked around and I have not had luck finding something that would work. I am still relatively novice to Unity and Scripting.

I have a script that is working on several different objects for various outcomes and one of those is to rotate an object using a slider from the GUI. Here is the code that is activating the slider GUI item and (hopefully) that will drive the rotate depending on the selected object:

if (needleActive == true){ //check if the
guiInsulinScript.rotateNeedle = true;
switch(checkTarget){
case “NeedleInsulin”:
needleTargetRotate = GameObject.Find(“Needle_Insulin_Complete_Primary”);
print("The Target is " + needleTargetRotate);
needleTargetRotate.transform.eulerAngles.y = guiInsulinScript.hSliderValue;
print("The slider is " + guiInsulinScript.hSliderValue);
print("The Needle is " + needleTargetRotate.transform.eulerAngles.y);
break;
case “NeedleTB”:
targetForExamine[9].transform.rotation.eulerAngles.x = guiInsulinScript.hSliderValue;
break;
case “Needle3ml”:
targetForExamine[10].transform.rotation.eulerAngles.x = guiInsulinScript.hSliderValue;
break;
}
} else {
guiInsulinScript.rotateNeedle = false;
}

If I change needleTargetRotate.transform.eulerAngles.y = guiInsulinScript.hSliderValue to transform.eulerAngles.y = guiInsulinScript.hSliderValue it rotates all of the objects this script is attached to at the same time. However, with the needleTargetRotate (or targetForExamine[8]) added, nothing will rotate. I am not sure if I am just trying to get the object incorrectly or if there is another issue that is keeping it from working.

Any help you can provide will be much appreciated.

Thanks in advance.

Do targetForExamine 9 and 10 work but 0 through 8 don’t? Otherwise how is targetForExamine populated?

As another possible lead, is there any way to label the object you need before you get to this point that way you can just throw in randomObject.transform.rotation.eulerAngles.x = guiInsulinScript.hSliderValue; instead of using GameObject.Find() since from what I understand that’s a rather expensive operation.

I am gathering targetForExamine via the Transform[ ] method and linking the object to the script in the Inspector. In another portion of the Update function adjacent to this code, I am triggering animations for each object and that works perfectly. I am assuming the problem with controlling the rotation via the slider has to do with how I am trying to talk to the object since it rotates all objects if I remove the references to anything trying to call a specific object.

As far as labeling the object, that might actually be what I am asking to do here. I really thought that targetForExamine[8].transform.rotation.eulerAngles.x = guiInsulinScript.hSliderValue would be the way to do since i can already call an animation with its array value but maybe there is something else I need to do instead to grab the targetForExamine[8] object? GameObject.Find() was just the last method I attempted last night that didn’t work so I am fine with not using it if it can be a costly operation.