I am trying to assign a getmouse button onto an object to play the animation. So far what I have done is this, I am not sure what I am doing wrong
Here’re the scripts;
UICloseScript:
var Panel0 : GameObject;
var Panel1 : GameObject;
var Panel2 : GameObject;
var Panel3 : GameObject;
var Panel4 : GameObject;
var Background : GameObject;
var LeftArrow : GameObject;
var RightArrow : GameObject;
var Blip : GameObject;
var BlipCentre : GameObject;
//var CloseButton : GameObject;
var TargetObject : GameObject;
var AnimationOpen : UICloseScript;
//var Animation : AnimationClip;
//var Object : GameObject;
//CloseButton.renderer.enabled = true;
function Update(){
if (Input.GetMouseButtonDown(0)){
print("pressed");
//animation.CrossFade("Close");
animation.Play("CloseButton");
//yield WaitForSeconds(animation.clip.length);
//yield WaitForSeconds (0.7);
Panel0.renderer.enabled = false;
Panel1.renderer.enabled = false;
Panel2.renderer.enabled = false;
Panel3.renderer.enabled = false;
Panel4.renderer.enabled = false;
//CloseButton.renderer.enabled = false;
Background.renderer.enabled = false;
LeftArrow.renderer.enabled = false;
RightArrow.renderer.enabled = false;
Blip.renderer.enabled = false;
BlipCentre.renderer.enabled = false;
//CloseButton.renderer.enabled = false;
//return;
//renderer.enabled = false;
//animation.Play("Open");
}
}
//yield WaitForSeconds(animation.clip.length);
I can see the animation plays but it plays the when I click onto another objects as well. I need to make it for a specific object somehow… Any ideas? Thanks
Hi…
looking your code, there is no target to press… so the program is reading a mouse button but is not reading where to click
you may use OnMouseUp() instead… previously setting collision to the object you want to click to…
I tought putting this script onto the button object should be enough
but I think I am wrong… So shall I change GetMouseDown part with OnMouseUp or is there any other way to achieve what I am trying to do. Thanks
Please guys help? How can i assign a target to read where I click ?
I think you should handle it in OnMouseUp instead of Update, it should be simpler and solve your problem.
I have tried something like that earlier but didnt work
It’s not playing the animation at all… Am I doing something wrong ? Thanks
function OnMouseUp(){
if (Input.GetMouseButtonDown(0)){
print("pressed");
//animation.CrossFade("Close");
animation.Play("CloseButton");
You don’t have to check for GetMouseButtonDown when you are in that event, because that event is already fired only when a mouse button has been released, so just cut off the “if” statement
Right, just sorted thank you
As I understand It is not possible to use this function for Iphone dev 
Then you can just improve your first code and add a raycast check besides GetMouseButtonDown in Update
THank you for the info, I am trying something like this on raycast thing… But I am getting an error about origin, Can you see what I am doing wrong ? Thanks again
var buttonhit : Transform;
var hitinfo : RaycastHit;
function update()
{
if(Physics.Raycast(origin,Vector3.down,hitinfo,2))
{
if (Input.GetMouseButtonDown(0)){
print("pressed");
//animation.CrossFade("Close");
animation.Play("CloseButton");
}
}
Here you can find a way to get a raycast from Input.mousePosition (remember that the gameobjects you want to get with raycast need a collider attached), you should really look into Scripting Reference and try its examples before ask…
Here is a gui button video tutorial, hopefully this helps! 