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 maryhary · Apr 12, 2012 at 12:45 PM · animationiphonetouchmultiple objects

iOS touch triggers the wrong object

Hello. Can someone tell me what I'm doing wrong? I have several objects in a scene, and I want to be able to tap them to to manipulate them in different ways. Some of the objects are fine, I tap them and they animate/whatever. But when I tap some other objects, an animation in a completely different object occurs. I feel like I'm missing something simple here and I think I've come across this question here before but I can't find it now.

Please help me :)

EDIT: this is the code in the js-script attached to the object I tap and want to animate:

  function Update () {
 
 }
 
 function FixedUpdate() {
 for(var touch : Touch in Input.touches) 
 {
     var ray : Ray = Camera.main.ScreenPointToRay(touch.position);
     
     if(touch.phase == TouchPhase.Ended) 
     {
         
         var hit : RaycastHit;
         
         if (Physics.Raycast (ray, hit, 100.0)) {
         //Debug.Log("Touched...");
         //var curX = Input.GetTouch(0).position.x;
         //var curY = Input.GetTouch(0).position.y;
         //Pos = Instantiate(curX, curY, 1000); 
         //Pos.rigidbody.AddForce(transform.forward * speed);
         rigidbody.AddForce(0, 1200, 0);
     }
 }
 }
 }

And this is the code in the cs-script attached to the object playing its animation:

     public class TouchBlueTeapot : MonoBehaviour {
     
     public Animation m_animation;
     
     // Use this for initialization
     void Start () {
         Debug.Log("started");
     }
     
     // Update is called once per frame
     void Update () {
     foreach (Touch touch in Input.touches)
             
 {
     Ray ray = Camera.main.ScreenPointToRay(touch.position);
             Debug.Log("RAY:" + ray.direction);
     
     if (touch.phase == TouchPhase.Began)
     {
         Debug.Log("touchphase position:" + touch.position);
         RaycastHit hit = new RaycastHit();
         
                 
         if (Physics.Raycast(ray, out hit, 1000))
         {
 
             
             Debug.Log("touched " + hit.transform.name);
     
             
                     gameObject.animation.Play();
                     
         }
     }
 }
     
     
     }
 }

Sorry if it looks kind of crappy...

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 Kleptomaniac · Apr 12, 2012 at 12:47 PM 0
Share

Could you please provide the code you are currently using? Also, just as a precaution (because it seems to happen a lot), could you make sure that when you do copy in your code, highlight the entire code, and press the 101010 button in the toolbar to format it correctly. :)

avatar image maryhary · Apr 12, 2012 at 12:56 PM 0
Share

Sure! Should I provide the code in the script attached to the object or also the script attached to the object being animated?

0 Replies

· Add your reply
  • Sort: 

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

Touch GUI texture to toogle animation 0 Answers

Unity iPhone: AddForce to Object after Touch 0 Answers

Android swipe from the top triggers onClick events 0 Answers

Input.GetAxis("Vertical") on touch devices. 2 Answers

How can I detect touch on anroid or iphone 2 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