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 AASonyKK · Oct 07, 2011 at 05:30 PM · c#touchobjects

Script when i touch an object it must do something

Hi,

I'm making a game for android and now i have a problem. :( I have a lot of objects (all clones created during the game) very near together. And i need to do a script that do this: When i touch one object it must change his position, only the object i have touched and not all the near objects. I can't write a script that can "select" an object when i touch it. I'm using C# and i'm blocked at this point. If you need more information ask me.

Please, I need your help. Thanks.

Comment
Add comment · Show 1
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 AASonyKK · Oct 09, 2011 at 04:28 PM 0
Share

I tried this

if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved) {

         Ray ray =   Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

         
         if (collider.Raycast(ray, out hit, 1000) )
         {
             
             move the object

         }
     }

But When i touch one of my clone (a prefab), all the near prefab change them position. I need a script that if i touch once only one clone need to change him position and not all the near prefab. (they are very very near).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by leonalchemist · Oct 07, 2011 at 07:29 PM

i think a very simple OnTriggerEnter will work

 void OnTriggerEnter (Collider Enemy)
 {
     if (Enemy.tag == "Player")
     {
         //something like
         gameObject.transform.position = some Vector3 position
     }
 }

make sure the tag on ur charatcer i set to 'Player' and the collider 'is Trigger' is checked. Im guessing its a prefab so u can attach the script to the prefab, and the OnTriggerEnter will only change the position of the object it hit cause the OnTriggerEnter event only take effect to the object u've hit.

Comment
Add comment · Show 4 · 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 AASonyKK · Oct 09, 2011 at 04:25 PM 0
Share

mmmm, it don't run. I don't know how to use this. But if all clones of prefab are set to Player, all of them change position, and not only once a time.

avatar image leonalchemist · Oct 10, 2011 at 05:34 PM 0
Share

have u manage to make it work, normally only the Collided object will make the script work so the transform.position should only change the position of the gameObject the player got hit with, thats why OnTriggerEnter is quite useful.

but when u say "When i touch one object it must change his position" as in with the touchscreen the is it a character on screen that collides with other objects? if its the 1st then i wont be able to help u further cause i dont know nothing bout how touch screen works.

avatar image AASonyKK · Oct 11, 2011 at 03:53 PM 0
Share

Yes, i want the object do this when i touch the screen (when i touch the object).

The problem is that when i touch with my finger i touch 2-3 objects and their change the position, but i want do: 1 touch = only 1 object change position.

avatar image leonalchemist · Oct 11, 2011 at 03:58 PM 0
Share

um well sry, thats above my knowledge :/

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

cant touch multiple objects on screen (c# , mobile) 0 Answers

Distribute terrain in zones 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Make Swipe Detection Longer? 0 Answers

Detect the swipe and add force respective to it? 3 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