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 Rgalaxy · Nov 23, 2013 at 03:46 PM · movementgui-buttonmovinggameobject

Moving an object with Clicking GUI Button

Hello, i have some problem with moving an object with GUI Button i had search and tried a lot of ways but it not successful..

What i tried to do is, how to make an object move(not snapping) into some point i appointed with GUI Button click..

i make the GUI, and i make this code

 function OnGUI() {

   if(GUI.Button(Rect(50,300,70,30),"Attack 1")){
      GameObject.Find("brawler_armoured").transform.position.x = -7;
      GameObject.Find("brawler_armoured").transform.position.y = -1.5;
      //Controller.Move(MoveSpeed*5) * Time.deltaTime;
   }
 }

with this code, my object could change position, to the point, but what i want is they move to there.. i really confused, my friend ask me to use time.deltatime.. but every time i look for the tutorial all using function Update() and the tutorial always about w,a,s,d key..

please anyone help me,, or if it's aldy answered and the problem is just the same, please give me the link :) thanks before.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by vividhelix · Nov 23, 2013 at 04:32 PM

Easiest thing is to use a tweening library, such as HOTween or iTween. They have movement functions, both their documentation is pretty good.

Alternatively, you could lerp the location yourself, the example here is pretty close to what you're looking for: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

Comment
Add comment · Show 1 · 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 Rgalaxy · Nov 24, 2013 at 10:16 AM 0
Share

Thanks vivid for the answer, but i think i dont go with motion first, i want so that when i click my gui button it move.. and ur examples is placed on update()..

the matter here is, the javascript file will attached to player, but $$anonymous$$e is attached to $$anonymous$$ain Camera.. and i'd like to know how to put my code on $$anonymous$$ain Camera, since my GUI is in my $$anonymous$$ain Camera..

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

How to make bullet move in the players forward direction at the same speed as the player that fired it, as well as in the bullets forward direction. 1 Answer

My object can't move left and right but only jump? 1 Answer

Character Movement won't work properly because of the rotation 1 Answer

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

Making a bubble level (not a game but work tool) 1 Answer


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