- Home /
Problem with transform.LookAt and if statement
I don't get any errors and I believe that his should definitely work, but it doesn't. anyone know why? (the speed variable and the playerNearby bool both work but the object never looks at the target.)
void Update ()
{
if (playerNearby == true && speed > 1.0f)
{
transform.LookAt(target);
}
}
Answer by fffMalzbier · Aug 29, 2016 at 09:36 AM
First make sure that the condition is actuality met. You can use a call of Debug.Log("Condition is met"); to make sure it is met.
Is there any other code that could overwrite the rotation of the lookAt afterwards (other script or maybe a animator)
yes right :
if (playerNearby == true && speed > 1.0f){
Debug.Log("i should rotate now");
transform.LookAt(target);
}
so if you didn't get this log in the console make sure again the variables are ok & the target transform handled in your script
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C#, Problem with If Statements and GO Position Comparisons. 1 Answer
If statement randomly not working 2 Answers
How to shorten multiple if statements ? 2 Answers