2D On Trigger Enter Not Working

Hi
I am trying to get a 2D sprite to disappear when clicked on, I have a 2D rigid body attached to the sprite as well as a 2D box collider but is not working.
This is the script I am trying to use.

using UnityEngine;
using System.Collections;

public class Balloon : MonoBehaviour {


	public SpriteRenderer Balloons = null;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void OnCollisionEnter2D(Collision2D coll) {

		if (Input.GetMouseButton(0))

			Balloons.GetComponent<SpriteRenderer>().enabled = false;
		    
	
	}
}

Thanks in advance

Your code and your words are saying two different things. If you are talking about clicking on a balloon with the mouse, the easiest solution is to have a script on the balloons with an [OnMouseDown()][1] function. [1]: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDown.html

2 Answers

2

Use a raycast and check for the objects tag.

I converted this to a comment, the "answer" box is used for solutions to the problem. Anyway one thing to try is to plug in your device before you open unity. Also make sure you've got adb drivers for your device. Also, make sure you've enabled developer options > usb debugging on your device.

I tried OnMouseDown() but you can click anywhere and the object will disappear, I am unsure how to use 2D raycast as I am just new.
This is the code.

using UnityEngine;
using System.Collections;

public class Balloon : MonoBehaviour {


	public SpriteRenderer Balloon1 = null;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
    void Update (){

		if (Input.GetMouseButton(0))
	    Balloon1.GetComponent<SpriteRenderer>().enabled = false;

}
} 

Thanks