- Home /
Open and close doors
I made a script to change de angle rotation in the object (door) but I can't deactivate the Main function when player is go away from door and Activate the Main function when player is near the door.
This is my script:
pragma strict
var AngleX : float = 0.0 ; var AngleY : float = 90.0 ; var AngleZ : float = 0.0 ;
private var targetValue: float = 0.0 ; private var currentValue : float = 0.0 ; private var cosing : float = 0.05 ;
var Target : GameObject;
var enter : boolean;
function Update () { currentValue = currentValue + (targetValue - currentValue)*cosing;
Target.transform.rotation = Quaternion.identity;
Target.transform.Rotate(0, currentValue, 0);
if(enter == true){ if(Input.GetKeyDown("e")){ targetValue = AngleY; currentValue = 0; } } if(enter == true){ if(Input.GetKeyDown("q")){ currentValue = AngleY; targetValue = 0.0; } } }
//Activate the Main function when player is near the door function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") { (enter) = true; } }
//Deactivate the Main function when player is go away from door function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") { (enter) = false; } }
I think is something wrong with the function OnTrigger please help me!!
Answer by selzero · Mar 04, 2013 at 06:12 PM
Take a look at the table at the bottom of this page:
http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html
Make sure you have the correct colliders set up.
Then use the OnCollision (or relevant) function, not update.