|
Hello I'm a bit of a noob so go easy... I'm trying to make a room escape game on unity, this is all I have so far...
For the first level shown above I just want to open the door when the mouse is looking at the door and the player clicks the left mouse button. I've tried many times and different ways to do this but I cannot accomplish this :( I have iTween Editor set up to play the animation of the door opening, which looks fine I just need a way of activating it to play the animation and load the next level once the door is opened. I have this bit of code already, but its not much use... Does anyone know how to make this work? Thanks in advance!
(comments are locked)
|
|
you could use a raycast method. the door will need a collider : http://unity3d.com/support/documentation/Components/class-BoxCollider.html then cast a ray (Raycast) : http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html if the raycast hit the door, then play animation. (raycast video) : http://www.unity3dstudent.com/2010/08/intermediate-i01-raycasting/ then you could write something like this : Thanks that worked... sort of, when ever I play the game on unity it doesn't always open the door when clicked, I have to first minimize unity and then open it back up for the door to open when I click. I then built and run the game but that seems the have the same problem, also when I minimize the browser I doesn't work (this is a browser based game), also this game has no character movement its just the scene as shown and you have to do certain puzzles to open the next level.
Jun 25 '12 at 07:59 PM
Keenan_Pearce
That is very strange, not sure why you have that going on. The unity player in a web-page needs to be active to accept input, but clicking on the unity player should make it active anyway. You could try some debugging to see what is going on. put this line after put this line after put this line after this should create some output in the console window, showing when the mouse is over the door, when the LMB is pressed and what collider the raycast hits. Run this (in Unity, not webplayer) without minimizing etc to see if the script and the input is working (it should). on my way out but shall check back and test for myself later.
Jun 26 '12 at 03:46 AM
alucardj
I've had a look and it seems to be the OnMouseEvent method. When the Raycast is in Update, it works fine. I have updated the answer, and changed the script so that it can be placed anywhere, just load your door in the Inspector. As long as the collider is on the var target : GameObject; this should work. tested =] if this script is part of the player, you could load several 'targets' and use the same raycast to check different colliders at the same time : target3 target4 FrontDoor KitchenDoor etc
Jun 26 '12 at 07:47 AM
alucardj
Omg thank you so much!
Jun 27 '12 at 05:31 PM
Keenan_Pearce
(comments are locked)
|
|
Omg thank you so much!!
(comments are locked)
|


does your door object have at least a box collider on it? If it has no collider than the on mouse enter will never fire off