Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Meriodoc · Sep 23, 2014 at 09:14 PM · animatormousemecanimtagstate

Macanim Mouse Buttons interaction c#

How can I make this work. I have set up 4 states in animator default being idle. I want the clicks to only work on this object...not on the others in the scene. So I figured TAGS? Please point me in the right direction. Thank you. Here's my code.

 using UnityEngine;
 using System.Collections;
 
 
 public class A_BlueFishScript : MonoBehaviour 
 {
     private Animator animator;
     private int State = 0;
 
     void Start () 
     {
         animator = this.GetComponent<Animator>();
         animator.SetInteger ("State", 0);
     }
 
     void Update () 
     {
 
         if (Input.GetMouseButtonDown(0) && gameObject.tag == "A_BlueFish")
             Debug.Log("Pressed left click for Rotate.");
                 animator.SetInteger ("State", 1);
                 
         
         if (Input.GetMouseButtonDown(1) && gameObject.tag == "A_BlueFish" )
             Debug.Log("Pressed right click for Zoom.");
                 animator.SetInteger ("State", 2);
         
         if (Input.GetMouseButtonDown(2) && gameObject.tag == "A_BlueFish")
             Debug.Log("Pressed middle click for Move.");
                 animator.SetInteger ("State", 3);
 
     }
 }

Comment
Add comment · Show 13
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 Meriodoc · Sep 23, 2014 at 09:55 PM 0
Share

State is an int(parameter) I set up in mecanim. Idle State = 0 and so on.

avatar image Freaking-Pingo · Sep 24, 2014 at 12:30 AM 0
Share

Have you remembered to change the tag of the GameObject? Based on your code, only objects that make use of the tag "A_BlueFish" should execute the said animation.

alt text

screenshot 2014-09-24 02.33.40.png (15.4 kB)
avatar image Meriodoc · Sep 24, 2014 at 05:38 AM 0
Share

Yes I did. Thanks for the input. I am getting the debug messages on screen when I click. 1. But I get that when I click anywhere on the screen. 2. There is no interaction with the Object. It is as if the tag isn't working at all. Is there another way? Layer, Sorting layer or Raycast hit maybe? I forgot to mention. This is a 2D game. Thanks.

avatar image Meriodoc · Oct 02, 2014 at 09:02 AM 0
Share

Can anybody help me please?

avatar image Baste · Oct 02, 2014 at 09:49 AM 0
Share

Have you set up transitions in your animator? If you get the debugs, animator.SetInteger is being called, so the problem is probably that you haven't set the transitions between the different states.

Also, the correct way to ensure that the correct object gets the inputs is to register input in a input manager script (only), and have the input manager send those inputs on to whatever needs to get that input.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fotaras · Oct 31, 2014 at 07:19 PM

Check this

MonoBehaviour.OnMouseDown

Comment
Add comment · 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

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

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NavMeshAgent animation - sliding 2 Answers

Not able to use a Vector as a condition in Mecanim? 2 Answers

Animator not registering changes in parameters. 0 Answers

How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers

How can I know if the currentAnimState is mirrored or not? 0 Answers


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