Question by
Ikrambandagi · Jul 02, 2018 at 09:38 AM ·
object movement
Object rotation as we see of the prefab in prefab window.
![alt text][2]Hi everyone, I am beginner in programming side and stuck in one place. I want to rotate my game object with mouse/touch. But I want to rotate it as we rotate our prefab while selecting it and rotate in the prefab window. I have written a script which rotates the object with X and y axis but it gets weird angle in the end due to which it is hard to reset it to its original position.
Thanks
Here is my script and the prefab window image:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotator : MonoBehaviour
{
public float rotationSpeedY = 2f;
public float rotationSpeedX = 5f;
//public float angleMinLimit, angleMaxLimit;
Quaternion objRotationY, objRotationX;
private GameObject myObject;
//public float yRotation = 5f;
private void OnMouseDrag()
{
objRotationY = Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * rotationSpeedY, -Vector3.right);
myObject.transform.rotation = myObject.transform.rotation * objRotationY;
objRotationX = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * rotationSpeedX, -Vector3.up);
myObject.transform.rotation = myObject.transform.rotation * objRotationX;
}
prefab-window.png
(282.9 kB)
Comment
Your answer
Follow this Question
Related Questions
What am I doing wrong? 0 Answers
apply force in camera direction 0 Answers
Object Movement Script,Need help with an enemy spawn / despawn script 0 Answers
Object and camera following mouse 0 Answers
How do I make the same 2d object to fall again and again? 0 Answers