How can I open a door when a sphere (ball) stands in front of it?

I have a cube ( door ) and a sphere(ball) how can I open the cube without raycasting.I tried using raycast but I have the ray only on one side and the door doesn’t open until I roll over with the wright side of the sphere.

The Angry Bots package has a few sliding door prefabs in the package, you can download the Angry Bots package and tinker with the doors to learn how they are configured, possibly modify them to your liking, or use them as a reference for configuring your own. Here’s a script from one of the doors, it does not use raycast, it uses colliders and triggers. I hope this helps a little:

#pragma strict

@script RequireComponent (SphereCollider)

private var target : GameObject;
private var sphereCollider : SphereCollider;
private var activeRadius : float;

function Awake () {
	target = transform.parent.gameObject;
	sphereCollider = GetComponent. ();
	activeRadius = sphereCollider.radius;

	Disable ();

function OnTriggerEnter (other : Collider) {
	if (other.tag == "Player" && target.transform.parent == transform) {
		Enable ();

function OnTriggerExit (other : Collider) {
	if (other.tag == "Player") {
		Disable ();

function Disable () {
	transform.parent = target.transform.parent;
	target.transform.parent = transform;
	target.SetActive (false);
	sphereCollider.radius = activeRadius;

function Enable () {
	target.transform.parent = transform.parent;
	target.SetActive (true);
	transform.parent = target.transform;
	sphereCollider.radius = activeRadius * 1.1;

Ok, so you want to open the door when the ball comes close, right?

Create a sphere colider for the door and scale it up a bit, this will be your sensor, when the sphere enters it the door will open. Also check Is Trigger in the collider.

And try applying this script to the door. Sorry if it doesn’t work or has errors, this is my first answer. :S

//drag and drop your door to the Game Object in the Inspector
var door : GameObject;
//using door speed as variable is not necessary but that way you can easily change
//it from the inspector
var doorSpeed : float = 1000;

//creates a variable coll
function OnCollisionEnter(coll:Collision)
//uses its collision to check if it colides with a object called Sphere
if( == "Sphere")
//Executes the OpenDoor function

function OpenDoor()
//insert door movement code here
//i just started this so idk how to make it move a certain distance
//so i just made the door a rigid body and applied force to it
//change "left" into any other direction if you need to

door.rigidbody.AddForce (Vector3.left * doorSpeed);