First sorry for bad English
I just trying to use this code to start using raycast :
function Update () {
if (Physics.Raycast(transform.position,transform.forward ,5))
{
Debug.Log('yes');
}
else Debug.Log('No');
}
I assign this code to first person controller and when distance to an object is less than 5 its message changes to “Yes” but after that message not change and it will be “yes” forever.
Please tell me where is my problem.
I use Unity 3D 4.5.2f1
I drag and drop raycast script on “First person controller”.
I change Debog.Log(“Yes”) to this :
Debug.Log("Yes" + hitPosition);
And at start console write “No” , then when player come near object , console write the hit position and then when i am away from the object , console still write the same position.
And note that position of two different place on object according to console are same!!!
I placed the script once and i get no error. I found that when there is no object in front of player , console stop sending message. it just can’t write “No”. It seem “If” condition is always true and “else” Commands can’t run.
Console screen shot :