I have a disc that will rotate when the user drags the mouse around it, however the disc will not fully rotate with my script, it works if you drag from the center of the disc to the left/right edge but not if you try to drag around the radius of the disc. I need the disc to fully rotate following the radius of the disc/mouse drag.
The script I am using is below:
using UnityEngine;
using System.Collections;
public class RotateDisc : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
void Update ()
{
bool turtle = false;
RaycastHit hit;
if (Input.GetMouseButton(0))
{
if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
turtle = false;
float x = -Input.GetAxis("Mouse X");
float y = -Input.GetAxis("Mouse Y");
float speed = 10;
transform.rotation *= Quaternion.AngleAxis(x*speed, Vector3.forward);
transform.rotation *= Quaternion.AngleAxis(y*speed, Vector3.forward);
}
}
}
}
Any suggestions or help would really be appreciated. 8) 8)
I could try that, would this make the camera look at the object to make it appear to be rotating?
I may have 2 objects rotating.
So the LookAt script would be edited to include a raycast ?
The rotation in the example script almost does the object rotation correctly, but stops half way.
no, the LookAt will make the object itself look at something, not the camera. So if you do a raycast and make an invisible gameobject move to where the hit position is, then you can make your disc look at the invisible gameobject…
P.S. I have been trying to figure out the offset / tiling option in Unity so that I can choose what part of my image/texture would be visible on my UV mapped disc (GameObject).
If I understand correctly, it should enable me to show the right hand side (or any other part) of the image instead of the whole image if desired?
Check out this post; at the bottom u find a script,
I’m pretty sure this is kind of what you’re looking for.
You just need tot adjust it to your preferences.
@Halo212: you’ve posted this question in several different places now. In future, please start only one thread for a given problem. We don’t mind if you bump that thread in the case that you don’t get a response. However, it is a nuisance to everyone if they are responding to you unaware of what other people have said in the other threads.