• 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 The Ghost · Jun 25, 2013 at 01:04 AM · animationmovementtouchmecanim

Trying to get Mecanim to work well with Touch Controls

Any help on getting Mecanim to work well with touch controls? Here's the movement script so far

 public class PlayerMovement : MonoBehaviour
 {
     public float speed = 1f;
     public Vector3 touchPoint;
     public static bool isMoving = false;
     
     void Update()
     {
         // Lerps to the last position touched, going to have to modify this
         // to only work when tapped not hold cause shooting will be hold.
         
         if (Input.touchCount > 0 )
         {
             // Shoots a ray where you touched the screen
             RaycastHit hit;
             // There was an error before. The tag must be main camera.
             Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
             
             if (Physics.Raycast(ray, out hit, Mathf.Infinity))
             {
                 // converts the touch point to unitys 3d worldspace Vector3
                 touchPoint = hit.point;                                                                         
             }
         }
         MoveToPos(touchPoint);
     }
     void MoveToPos(Vector3 touchPoint)
     {
         isMoving = true;              
         gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(touchPoint.x, 10, touchPoint.z), speed * Time.deltaTime);    // LAWL this had to be z even tho im using y for droid , wasted alot of time on that.  
         //gameObject.transform.LookAt(touchpoint);
     }
 }
 

I want the character to switch from Idle to running. I tried using the sneak tut as a basis for this and got the hashes up but Unity gives an error with the script here:

  anim = GetComponent<Animator>();
  hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
  anim.SetLayerWeight(1, 1f);

any help would be appreciated.

Comment
Add comment · Show 2
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 voncarp · Jun 25, 2013 at 04:35 AM 0
Share

whats the error? it doesn't look like you have anything accessing the Animator. Your animations aren't going to change unless you set up the animator and access the variables as needed.

avatar image The Ghost · Jun 25, 2013 at 02:02 PM 0
Share
 anim = GetComponent<Animator>();
 hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<HashIDs>();
 anim.SetLayerWeight(1, 1f);
 
 This piece of code was supposed to access the editor but it gave me these errors:

error CS0103: The name Tags' does not exist in the current context error CS1502: The best overloaded method match for UnityEngine.GameObject.FindGameObjectWithTag(string)' has some invalid arguments

error CS1503: Argument #1' cannot convert object' expression to type `string'

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by The Ghost · Jun 30, 2013 at 02:52 AM

My solution to this was to use

public Animator anim;

and

anim.SetFloat("Speed", speed); anim.SetFloat("Move", isMoving);

instead.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Mecanim blend moves character? 1 Answer

Help with Animator has not been initialized error 5 Answers

Animate mecanim character only from script 1 Answer

Third-person character animations based on World-relative input and Y-rotation (looking at mouse position) 1 Answer

How to move a character with animation on Android? 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