Need help with C# script
I'm trying to create an app where you pop bubbles when you click or touch on them I have it so the bubbles pop when you click but it doesn't matter where you click you can click anywhere on the screen you don't have to click the bubbles and they pop I need it so the bubbles pop when you click on them not anywhere else here is the script I have I would appreciate any help you can provide Thank you
Answer by Susajin · Dec 14, 2015 at 10:16 AM
use the OnMouseDown() method
The on mouse down does the same thing the problem I'm having is when I click anywhere on the page the animation in gauges which makes the bubbles pop I could click on the top left corner where there's nothing at all and the bubbles will still pop I'm trying to get it so when I click on the bubble the animation in gauges and nowhere else that's the problem I'm having
What makes it more challenging is that the bubbles automatically float up so I can't add in a click on vector location to engage animation because they are never in the same spot that continuously floating up out of screen
i assume these bubbles have a collider and script attached, did you use On$$anonymous$$ouseDown() on the attached script? It has to be attached to the Bubble (GameObject) to work. Then it should only be called when clicked on these individual bubbles
Answer by chaosapplications · Dec 15, 2015 at 03:46 AM
I tried the OnMouseDown() but I got Error CS0117 'Input' does not contain a definition for 'OnMouseDown'
This is the script I have been working with I know its missing something I just don't know what
using UnityEngine;
public class BubblePop : MonoBehaviour
{
public GameObject animBubble;
public Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void Update()
{
if (Input.GetMouseButton(0))
animator.SetInteger("bubbleState", 1);
{
animBubble.GetComponent<Animation>().Play("bubble");
animator.SetInteger("bubbleState", 0);
}
}
}
here are pics of how my game object is set up
Now this just popped up
Error CS0246 The type or namespace name 'List<$$anonymous$$aterial>' could not be found (are you missing a using directive or an assembly reference?)
$$anonymous$$ake sure you dont have a class named Input (if you have rename it) because Unity has already a class named Input and it could be causing a problem, if not try with this code:
using UnityEngine;
public class BubblePop : $$anonymous$$onoBehaviour
{
public GameObject animBubble;
public Animator animator;
void Start()
{
// make sure you have a Animator component attached to this
// GameObject
animator = GetComponent<Animator>();
}
void On$$anonymous$$ouseDown()
{
// here you are taking it from the Animation component from
// animBubble GameObject (why?)
animBubble.GetComponent<Animation>().Play("bubble");
animator.SetInteger("bubbleState", 0);
}
}
make sure you delelete/comment out every Input.Get$$anonymous$$ouseButton(0) on every script because this returns true every time you press the left mouse on the game screen.