- Home /
Strange rotation problem? need to remove then re-Add Component
hello, I'm creating a side scroller - when the character gets to the end of a level, the camera changes to a top down view of the Boss Area - all of this works great, except in order for my character to fire projectiles at the mouse (using MouseLookAt script), I have to rotate the players mesh -90 degrees as soon as he enters the play area
public class PlayerMeshRotation : MonoBehaviour
{
public int useLookAt;
void Start ()
{
useLookAt = 0;
}
void Update()
{
useLookAt = PlayerMovement.lookAt;
while(useLookAt == 1)
{
transform.Rotate (0,-90,0);
break;
}
if(useLookAt == 1)
{
useLookAt = 2;
}
}
}
However, the first time I load the scene, this doesn't work - I have to "Remove Component" (that script), then "Add Component" (that same script) - resetting the script does nothing. Any ideas whats happening?
There's not really enough information here to help easily, what is Player$$anonymous$$ovement.lookAt? You are never setting it but you seem to always want it to be 2 if it returns 1 but why not then just recode whatever asked to be 2 to be 1.
I'm not sure this is your problem but I don't like the look of that while loop, it is an infinite loop as you are not changing useLookAt within the loop. I presume the only reason it hasn't crashed unity is because it's in Update so it is recalled each frame anyway...
You aren't even using useLookAt to do anything in this script so what is the point of it?
I think this is just a basic version of what his script looks like.
Answer by Ardmark · May 12, 2014 at 02:47 PM
Are you setting PlayerMovement.lookat in the Inspector? I'm wondering if PlayerMovement.lookat is being changed somewhere before loading the scene (or perhaps it is retaining it's value from the previous scene), but if you have it set to 1 in the Inspector then reloading the component would allow the script to work? Just a thought.
Your answer
Follow this Question
Related Questions
Quaternion Rotation On Specific Axis Issue 0 Answers
iTween - Rotation Add get's uneven after several rotations 2 Answers
Weird issue with clamp on Rotation 1 Answer
Blender Mesh rotation 3 Answers
Child lossyScale changes after setting localRotation 1 Answer