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 Der_Kevin · Jul 17, 2013 at 03:04 PM · movementitweentargetmovingclicking

itween: targeting differnt gameobjects after mousecklick

Hey guys. Iam trying to archive the following thing:

i have 2 boxes and one character which is controlled with the third person controller in my game. and all i want to do is, that the character will move automaticly to the box when i clicked it.

i tried it with itween (visualEditor). works verry well with one box. but only when marked it as "play automaticly" because i have no idea how i call the itween function only when i click one box. so, this would be my first question:

how can i call the itween function when i click on the box?

second question: i have two boxes. and at the moment, the itween script is put onto the player. so that means if i put 20 boxes in the game. there have to be 20 itween scripts in the player object? isnt there a better solution for this?

thanks for help

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 andytouch · Jul 18, 2013 at 12:16 PM 0
Share

How are you detecting when the player has clicked on the box? By a Raycast from the camera or in a 'On$$anonymous$$ouseDown' function in a script that is attached to the box?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DannyB · Jul 20, 2013 at 03:12 PM

You do not need 20 iTween scripts, and you do not need to use the visual iTween editor.

Assuming you know how to communicate between two different game objects and to send variables between them, the basic logic for such implementation is simple but may vary depending on your situation.

In general: The player object should listen to tap events on the box, when any box is tapped, the player decides what to do with it.

You can implement it with C# events, with Unity's SendMessage, or using publicly exposed methods on the player.

Example for the latter:

 // In player script
 public void OnBoxTap( GameObject box ) {
     iTween.MoveTo( gameObject, iTween.Hash(
         "position", box.transform.position,
         "time"    , 1
     ));
 }

 // In box script
 public PlayerClass player;

 void OnMouseDown() {
     player.OnBoxTap( box );
 }
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

17 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

Related Questions

Move object from A to B on sphere 2 Answers

How do you create random paths in iTween? 0 Answers

help with target in my fps game ? 0 Answers

Move player to specific location and avoid obstacle. 2 Answers

iTween for Dynamically Moving Objects around a Sphere 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