- Home /
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 On$$anonymous$$ouseDown() function.
Answer by shona1209 · Dec 17, 2013 at 02:15 PM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613124317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
How to make 2D grass platforms? 1 Answer
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
How do I export my GAME!!! 1 Answer