Point and Click Door Opening

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…

alt text

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 :frowning:

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…

var target : GameObject;
var eventName1 : String;
var sound1 : AudioClip;

function OnMouseEnter (){
if (Input.GetMouseButtonDown(0)){
iTweenEvent.GetEvent(target, eventName1).Play();
audio.clip = sound1;
audio.Play ();
}
}

function OnMouseExit (){
}

function Update (){
}

Does anyone know how to make this work?
Thanks in advance!

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 :

#pragma strict

var target : GameObject;
var eventName1 : String;
var sound1 : AudioClip;

function Update (){
	
	if (Input.GetMouseButtonDown(0)){
		
		var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		var hit : RaycastHit;
		
		if (Physics.Raycast (ray, hit)) {
			
			// * For When the script is on the Door object
			//if(hit.collider.gameObject == this.transform.gameObject){
			
			// * For When the door is loaded as  target : GameObject;
			if(hit.collider.gameObject == target){
			
				iTweenEvent.GetEvent(target, eventName1).Play();
				audio.clip = sound1;
				audio.Play ();
				
				// my door animation - for testing
				//target.transform.parent.animation.Play("Door_Open");
			}
		}
	}
}

Omg thank you so much!!