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