using UnityEngine;
using System.Collections;
public class CamerasScript : MonoBehaviour {
public bool airC; //Air condition is on or off
public float TurnRight; //How much the camera will turn right
public float TurnLeft; //How much the camera will turn left
public float Speed; //Speed that the camera will turn
//Start
IEnumerator Start(){
while (true) {
//First Wait for 2 seconds
yield return new WaitForSeconds(2);
//Then set rotRight
Quaternion rotRight =new Quaternion(transform.rotation.x,TurnRight,transform.rotation.z,transform.rotation.w);
//And rotate the camera using rotRight
transform.rotation = Quaternion.Slerp(transform.rotation, rotRight, Speed*Time.deltaTime);
//Wait for 2 seconds
yield return new WaitForSeconds(2);
//Set rot Left
Quaternion rotLeft =new Quaternion(transform.rotation.x,TurnLeft,transform.rotation.z,transform.rotation.w);
//And turn Left
transform.rotation = Quaternion.Slerp(transform.rotation, rotLeft, Speed*Time.deltaTime);
}
}
}
Well, my object actually rotates, but, its rotating to the wrong direction, and i already checked is the direction is negative or positive, also, its changing z and y axis when its not supposed to, and its not smoothly rotating when its slerp. Help!
---------------------EDIT--------------------------------
using UnityEngine;
using System.Collections;
public class CamerasScript : MonoBehaviour {
public bool airC; //Air condition is on or off
public float TurnRight; //How much the camera will turn right
public float TurnLeft; //How much the camera will turn left
public float Speed; //Speed that the camera will turn
bool TurnR;
bool TurnL;
float yValue;
void Update(){
if(TurnR){
Quaternion rotRight = Quaternion.Euler(transform.rotation.x,transform.rotation.y + TurnRight,transform.rotation.z);
transform.rotation = Quaternion.Slerp(transform.rotation, rotRight, Speed);
}
if(TurnL){
Quaternion rotLeft =Quaternion.Euler(transform.rotation.x,transform.rotation.y - TurnLeft,transform.rotation.z);
transform.rotation = Quaternion.Slerp(transform.rotation, rotLeft, Speed);
}
}
void Awake(){
yValue = transform.rotation.y;
}
//Start
IEnumerator Start(){
yield return new WaitForSeconds(2);
while (true) {
//Then set rotRight
if(transform.rotation.y<yValue+TurnRight){
TurnL = false;
TurnR = true;
}
else{
TurnR = false;
yield return new WaitForSeconds(2);
}//lol
if(transform.rotation.y>yValue){
TurnL = true;
TurnR = false;
}
else{
TurnL = false;
yield return new WaitForSeconds(2);
}
}
}
}
Im not sure if this is working or not becouse unity crashes
I tryed all of what you guys said
OK now this is want i want to do. You know those security cameras from fnaf. So what i want to do is that the game object rotates like the cameras from fnaf.