touch game objects on ios

Hello,

I ported a pc project to the iPad today and I noticed my script for opening doors wasn’t working anymore, this script gets triggered when the player clicks the door game object.
I figured I needed to use ray cast for this and yes I can open my door now using this script

 var studioBlock : Transform; // blocker behind the door to stop you entering a room
private var doorObject : GameObject; // the door gameobject (has a collider)
var doorName = "stdr"; // name of the door gameobject
private var hit : RaycastHit;
private var ray : Ray;
private var touchpos : Touch;

function Start(){

doorObject = GameObject.Find(doorName);
	
}

function FixedUpdate (){
	if (Input.touchCount > 0) {
		ray = Camera.main.ScreenPointToRay(touchpos.position); //I can't get touch.position to work
		Debug.DrawLine(ray.origin,ray.direction * 1000);
		if (Physics.Raycast(ray.origin, ray.direction * 1000,hit)){
			if (hit.collider.tag == "stdr"){
				doorObject.transform.animation.Play();// plays the door animation
				studioBlock.position.y = -100;// removes the room blocker
				Destroy(this);// destroys the script so you can't spam the door
			}
		}
	}
}

however the door only opens if the character is really really close to it, and also it only responds to touches on the touch pads in the bottom corners not when I just tap the door in the center of the screen.
I’m guessing the character controller script is conflicting with my script.
anyone any suggestions?

Dennis

p.s. I already posted this on the unity forum but people couldn’t really help me there

var studioBlock : Transform; // blocker behind the door to stop you entering a room
private var doorObject : GameObject; // the door gameobject (has a collider)
var doorName = “door”; // name of the door gameobject
private var hit : RaycastHit;
private var ray : Ray;
private var touchpos : Touch;

function Start(){

doorObject = GameObject.Find(doorName);

}

function Update (){
       ray = Camera.main.ScreenPointToRay(Input.mousePosition); //I can't get touch.position to work
       //Debug.DrawLine(ray.origin,ray.direction * 1000);
       
       if(Input.GetMouseButtonUp(0))
		{
			if(Physics.Raycast(ray,hit,1000))
			{
				if(hit.collider.gameObject.name == "door")
				{
					 Debug.Log("door");
					 studioBlock.position.y = -100;
				}
			}
		}
}

here it is your answer. its working well… you’re confusing much in your coding…you have to attach script into main camera…because check the “ray, you’re making ray from main camera”. no need of lot variable like string name and lot…

i tested this…and sure it’ll work…