Preinformation : Using Kinect v2 and Unity3D v5.4
Background : I have a parent GameObject
, which is a 3D model (eg a MacBook). This parent GameObject
is composed of several child GameObjects
. These child GameObjects
are the smaller Details of the 3D model (eg Display, USB-Port, Keyboard etc.). The MacBook itself can be rotated and scaled. What i want to do is fanning out these child GameObjects
proportional when using the mousewheel.
Problem : How do i implement this fan-out mechanism, independent of the current rotation of the parent GameObject
.
The image makes it hopefully more clear. The rectangles are representing child GameObjects
.
Thanks in advance :)
If you want to just change distance between your parent and childs add this to your child objects:
void Update ()
{
transform.localPosition += (transform.localPosition.normalized * Input.GetAxis("Mouse ScrollWheel") * 0.4f);
}
Or this to your parent:
void Update ()
{
for (int i = 0; i < transform.childCount; i++)
{
Transform t = transform.GetChild(i);
t.localPosition += t.localPosition.normalized * Input.GetAxis("Mouse ScrollWheel") * 0.4f;
}
}
Edit:
But if you want them to follow their forward direction use this rather:
void Update ()
{
transform.localPosition += ((transform.localRotation * Vector3.forward) * Input.GetAxis("Mouse ScrollWheel") * 0.4f);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.