Rotate object with another object in Unity 3D

Advertisemen






Rotate object with another object in Unity 3D

Simplest way to make joystick in unity 3d, rotating object with another object.

If you like to copy and paste the full length of code used in this video :

using UnityEngine;
using System.Collections;

public class rotObj : MonoBehaviour 
{
    float rotSpeed = 20;

    void OnMouseDrag()
    {
        float rotX = Input.GetAxis("Mouse X")*rotSpeed*Mathf.Deg2Rad;
        float rotY = Input.GetAxis("Mouse Y")*rotSpeed*Mathf.Deg2Rad;

        transform.RotateAround(Vector3.up, -rotX);
        transform.RotateAround(Vector3.right, rotY);
    }
}



using UnityEngine;
using System.Collections;

public class rotAnotherObj : MonoBehaviour 
{
    public GameObject obj;

    void Update () 
    {
        transform.rotation = obj.transform.rotation;
    }
}

If you like to see how to rotate an object in unity 3d, watch this video :
https://www.youtube.com/watch?v=S3pjBQObC90

Thanks for watching.
Please subscribe for more videos.

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D