- Home /
C# locking Main Camera's Rotations
Hi everyone, how do you lock the Main Camera's rotations? I tried putting the following below in update but I get this error expression denotes 'type' where a 'variable' 'value' or 'method group' was expected.
Camera.main.transform.rotation = Vector3(0,0,0);
Answer by robertbu · May 29, 2013 at 01:50 AM
I'm not sure what you mean by "locking" since the camera will only move if there is a script attached that moves it. But in terms of the above, transform.rotation is a Quaternion, not a Vector3. So to set a Quaternion to no rotation, use Quaternion.identity;
Camera.main.transform.rotation = Quaternion.identity;
You could also use eulerAngles which is a Vector3:
Camera.main.transform.eulerAngles = Vector3(0,0,0);
I'm still getting the same error. I'm not sure what the right ter$$anonymous$$ology is for what I want to do. I just want to make it so the main camera can not rotate in any of the axes.
Your error you mention is not with the either of the two lines above. For example run this script:
function Start () {
Camera.main.transform.rotation = Quaternion.identity;
Camera.main.transform.eulerAngles = Vector3(0,0,0);
}
If you double-click on the error in the console, it will highlight the line of the error in $$anonymous$$onodevelop. Also if this code is to be executed to counteract some other code that is rotating the camera, you will need to place it in LateUpdate() rather than in Update().
The console says that the Camera.main.transform.eulerAngles is causing the error. I have no idea why this is happening.
The Javascript version works fine. $$anonymous$$y guess is that C# uses something different. I'm not sure how to convert it. Does it look different in C#? Here is what I have currently.
void LateUpdate(){
Camera.main.transform.rotation = Quaternion.identity;
Camera.main.transform.eulerAngles = Vector3(0,0,0);
}
Ahhhh. C#:
Camera.main.transform.eulerAngles = new Vector3(0,0,0); The Quaternion.identy will work for both.
Your answer
Follow this Question
Related Questions
C# FP_Camera not following Character Controller 0 Answers
C# GameObjectList not Setting Parent 0 Answers
C# Transform Issues 1 Answer
C# The call is ambiguous between the following methods or properties 1 Answer
C# Smoothing Out transform.Translate 4 Answers