- Home /
Transform.RotateAround / Obsolete / solution?
Hi,
This is a simple script for rotating gameobject with mousedown. Everything fine, but I'm getting a warning : UnityEngine.Transform.RotateAround(UnityEngine.Vector3, float)' is obsolete: use Transform.Rotate instead.' No big deal I guess, but when I try to change .RotateAround to .Rotate or any other solutions I've come up with, ingame rotation isn't perfect. Any ideas? Thx.
using UnityEngine;
using System.Collections;
public class RotateUseMouse : MonoBehaviour {
public float sensitivityX = 10.0f;
public float sensitivityY = 10.0f;
public Transform cameraItem;
public bool down = false;
void Start () {
}
void Update () {
if( Input.GetMouseButtonDown( 0 ) )
down = true;
else if( Input.GetMouseButtonUp( 0 ) )
down = false;
if( down ) {
float rotationX = Input.GetAxis("Mouse X") * sensitivityX;
float rotationY = Input.GetAxis("Mouse Y") * sensitivityY;
transform.RotateAround( cameraItem.up, -Mathf.Deg2Rad * rotationX );
transform.RotateAround( cameraItem.right, Mathf.Deg2Rad * rotationY );
}
}
}
Answer by Sajidfarooq · Sep 05, 2013 at 07:36 PM
Use the second overload of transform.rotate:
void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo);
Its the same as transform.RotateAround. The "relativeTo" is the point you want to rotate around.
All good now. No more warning and the rotation is perfect. Thanks a lot.
This is wrong. Space is an enum it is not the point you want to rotate around.
public enum Space
{
World = 0,
Self = 1,
}
See the answers here: http://answers.unity3d.com/questions/47115/vector3-rotate-around.html
Your answer