Hello I have a big problem. I like to make my script door active from a distance. the situation is that my door has a script to be open when i press a keyboard such us i in my case. but i like that this script be active when the player is near the door and not from the bigenning of the game. I tried a simple script with raycast but that dosn't work
this is the script
I have created a script that move a door, you can alter to rotate: Some variables are in portuguese (I'm from Brazil, sorry), but I explan each one:
Person: The character that you control.
Distancia: Min distance to open door.
toWhere : To where the door would move e.g:.
Up x:0 y:2 z:0,
Left: x: -5 y:0 z:0
Misc: x:5 y:2 z:-3
answered Jan 11 '11 at 02:02 PM
You don't need a RayCast for that. You can use a simple distance check:
(Note you should always use sqrMagnitude and the square in the comparison, instead of magnitude, due to performance reasons)
Another method would be to create a collider around your door, and only test for the key event if the player is inside that collider:
A note regarding your code, you always cast your ray straight forward, so you will only get a hit if you actually directly look at the door(-collider), which might be the reason your code doesn't seem to work.
answered Aug 07 '10 at 03:34 PM
I try it but it dosn't work with me. i'm new with scripting in unity so i found a problem to write a script. Thanks for your help
answered Aug 07 '10 at 06:41 PM