Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by chaosapplications · Dec 14, 2015 at 10:01 AM · c#scripting problem

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 alt text

alt text

rps20151214-010510-198.jpg (92.1 kB)
rps20151214-010405-380.jpg (86.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Susajin · Dec 14, 2015 at 10:16 AM

use the OnMouseDown() method

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chaosapplications · Dec 14, 2015 at 07:32 PM 0
Share

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

avatar image chaosapplications · Dec 14, 2015 at 07:34 PM 0
Share

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

avatar image Susajin chaosapplications · Dec 14, 2015 at 09:33 PM 0
Share

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

avatar image
0

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

alt text

alt text


1.png (327.5 kB)
2.png (325.9 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chaosapplications · Dec 15, 2015 at 04:01 AM 0
Share

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?)

avatar image Susajin chaosapplications · Dec 15, 2015 at 10:28 AM 0
Share

$$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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to add a editing option to variables in a script in Inspector? 0 Answers

How to create buttons with script? 0 Answers

Side-scrolling Enemy AI not shooting in the right direction 0 Answers

How to make a random object generator that responds to simple touch? 0 Answers

Scripting Errors 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges