Hello Community,
Trying to create a 3D main menu here. The main camera have to rotate around a single point to bring into the FOV other 3D buttons. So click on “Settings” to rotate the camera to the Settings Menu. The main camera is a chid of the object CameraCenter (tagged with “CameraCenter”) where the rotation should be applied to.
My actual code is failing to work the way it should. The Rotation stops after few degrees. Where is my mistake?
#pragma strict
// button variables
var Title = false;
var Play = false;
var Settings = false;
var Quit = false;
var Back = false;
var ButtonSmooth = 2.0;
var ButtonMove = 2.0;
private var mouseover : int;
private var defaultPos : Vector3;
private var newPos : Vector3;
// camera variables
var CameraRotatinonSmooth = 2.0;
var CameraRotationAngle = 180;
var CameraCenter : GameObject;
private var defaultRot : Vector3;
private var newRot : Vector3;
function Start()
{
CameraCenter = GameObject.FindWithTag("CameraCenter");
defaultPos = transform.position;
newPos = new Vector3 (defaultPos.x, defaultPos.y, defaultPos.z + ButtonMove);
defaultRot = transform.eulerAngles;
newRot = new Vector3 (defaultRot.x, defaultRot.y + CameraRotationAngle, defaultRot.z);
}
// buttons moving toward camera
function Update ()
{
if(mouseover == 1)
{
renderer.material.color = Color.blue;
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * ButtonSmooth);
}
if(mouseover == 0)
{
renderer.material.color = Color.white;
transform.position = Vector3.Lerp(transform.position, defaultPos, Time.deltaTime * ButtonSmooth);
}
}
function OnMouseEnter()
{
mouseover = 1;
}
function OnMouseExit()
{
mouseover = 0;
}
function OnMouseDown()
{
if(Title)
{
// DO SOMETHING NICE
}
if(Play)
{
Application.LoadLevel(1);
}
if(Settings)//camera rotation to settings part
{
CameraCenter.transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, newRot, Time.deltaTime * CameraRotatinonSmooth);
}
if(Back)//camera rotation back to main menu
{
CameraCenter.transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * CameraRotatinonSmooth);
}
else
{
Application.Quit();
}
}
Ps. already tryed to commit the rotation via CameraCenter.animation.Play. Works fine, but i would apritiate a script only solution to have more tuning possibilities.