Is OnMouseUpAsButton() can be called only once ?
void OnMouseUpAsButton(){
if (swt == 0) {
door.Play ("Open"); // Open the 'Door'
swt = 1; // Switch
} else {
door.Play ("Close"); // Close the 'Door'
swt = 0; // Switch
}
}
Answer by Vivek-Joshi · Sep 21, 2015 at 06:43 AM
Whenever you click on the object where you want the function to be called OnMouseUpButton, it will be called every time. Keep the script on the object where you are clicking. Also keep a collider on the same object.
You can use Boolean to check whether to play it or not. (Like you showed in your own code)
But yes, it will be called every time.
If you want it to be played only once, you can try,
public bool isClickedOnce;
void OnMouseUpAsButton()
{
if(!isClickedOnce){
//Do something you want for the first time...
isClickedOnce=true;
}
}
Answer by Xspeed · Sep 26, 2015 at 04:58 PM
Thank you for your reply MR. @Vivek Joshi.
The problem is on collider. The colliders are not moved (Animated) with the Mesh. they are invisible, so i cannot find it. Now i have added all colliders into the door. and made some changes in script. So now i can open close the door easily.
There Is No Problem with the script or Game engine