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;
}
}
asked
May 02 '11 at 10:11 PM
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
I've tried it with: Void OnMouseEnter() { print("Entered"); } But even when I hover over it, it doesn't print the line.