x


OnMouseUp not working

I've coded a basic toolbox and when I click on an object it should do something. Now the problem I have is that the OnMouseUp doesn't work. I've tested it with OnMouseEnter and print some random line, but that doesn't do anything either.

It's a 2D game, so at first I thought it might be the camera, so I moved it a bit closer to the objects and that seemed to work for a few times. But now again, nothing responds on click.

Here's the code I'm currently using, I haven't changed anything from the point that it did work.

It does have a sphere collider and a rigidbody that is Kineamatic and doesn't use gravity.


using UnityEngine; using System.Collections;

public class BlackHoleScript : MonoBehaviour {

public ToolBox m_ToolBox = null;
public Transform Paper;
public AudioClip SoundClip = null;

void Start() {
    gameObject.AddComponent<AudioSource>();
    audio.clip = SoundClip;
    audio.loop = true;
    audio.rolloffMode = AudioRolloffMode.Linear;
    audio.maxDistance = 10.0F;
    audio.Play();
}

void Update() {
    if (audio.volume == 0) audio.Stop();
}

void OnMouseUp() {
    if (m_ToolBox.GetActiveTool() == "Paper") {
        iTween.ValueTo(gameObject, iTween.Hash("from",audio.volume, "to",0.0F, "time", 1.0F, "onUpdate","VolumeTo"));

        m_ToolBox.SetActiveTool("Nothing");
        m_ToolBox.SetPaper(m_ToolBox.GetPaper() - 1);
        m_ToolBox.SetToolBoxActive(false);
        Destroy(collider);

        Vector3 position = new Vector3(transform.position.x, transform.position.y, 0.3F);
        Instantiate(Paper, position, transform.rotation);
    }
}

void VolumeTo(float value){
    audio.volume = value;
}

}

more ▼

asked May 02 '11 at 10:11 PM

Thomas 7 gravatar image

Thomas 7
21 1 1 4

Add in a Print("test"); an to make sure OnMouseDown is being pressed. And add another one inside your if to make sure that condition is getting satisfied

May 02 '11 at 10:17 PM GesterX

I've tried it with: Void OnMouseEnter() { print("Entered"); } But even when I hover over it, it doesn't print the line.

May 02 '11 at 10:22 PM Thomas 7
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You need a collider on the object, or else it has to be a GUI element (GUIText/GUITexture).

more ▼

answered May 02 '11 at 10:16 PM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

It actually has a Sphere collider but still doesn't work.

May 02 '11 at 10:17 PM Thomas 7
(comments are locked)
10|3000 characters needed characters left

Ok, apparently it was because the toolbox I added came directly from a prefab and not the object in my scene. That fixed it and it now works fine.

more ▼

answered May 02 '11 at 10:53 PM

Thomas 7 gravatar image

Thomas 7
21 1 1 4

Ah, thats a mistake we've all made ;)

May 02 '11 at 10:55 PM Joshua
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x33
x18

asked: May 02 '11 at 10:11 PM

Seen: 1506 times

Last Updated: May 02 '11 at 10:24 PM