I’m not really even sure how to go about asking this, but here goes. My overall goal is to make a character’s eyes move by adjusting the mainTextureOffset by using the rotation of some bones in the character’s eyes as the x and y values.
So I am trying to assign a transform variable on a script that I have attached to a character’s eyes. Problem is that the character is created from a prefab on start, so I can’t simply drop the object in the transform slot. I need to assign the transform through scripting. The eye bone is in the same object as the eye with the texture, but down a different branch of the hierarchy. So how would I access the rotation transform for the eye bone?
Here is my script so far. It works as I need it to with the exception of assigning that transform variable.
var eyeBone : Transform;
function Start ()
{
eyeBone = //Not sure what I need here.
}
function Update ()
{
var eyeBoneAngleX = eyeBone.transform.localEulerAngles.x;
var eyeBoneAngleY = eyeBone.transform.localEulerAngles.y;
renderer.material.mainTextureOffset = Vector2(eyeBoneAngleX,eyeBoneAngleY);
}
First try making an instance of the object in your scene and then just drag the child object “Eyes” into the public transfrom then at the top of the Inspector there is an apply button click that and this reference will be saved in the prefab.
or
on line five where you wrote
eyeBone = //Not sure what I need here.
you can use something similar to
eyeBone = transform.Find("eye").transform
now i dont know what the path is to your eye bone but you may need to path from the object with your script to it like such
I tried this early on, but it still wasn’t working right, because it needs to start from the root. So I finally learned I needed to add in “root” to let it know that I wanted it to start searching from the top of this object’s hierarchy.