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 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;
}
}
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
Tidak ada komentar:
Posting Komentar