best function

I have created a door that i want to open automatically when the player gets close enough to trigger the trigger area what function should I use. I have been tring OnTriggerEnter but can not seemto get the first part of the argument to be accepted`

var player = gameobject.tag(“Player”);
function OnTriggerEnter(player : collider)

function OnTriggerEnter (CharacterController : Collider)function OnCollisionEnter(collision : Collision){ if(collision.gameObject.tag == "Player"

those are the three i have tried with no sucsess`

I would just use this script:

var rayCastLength = 5;

function Update()
{	
var hit : RaycastHit;

//check if we're colliding
if(Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
{
	//...with a door
	if(hit.collider.gameObject.tag == "door")
	{
		//open the door
		hit.collider.gameObject.animation.Play("door_open");
	}
}

}

The animation would be named “door_open” - stated in the script
And the tag for the door has to be “door”.

Hope this helps.

  • Felipe