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 alberpb · Jan 15, 2015 at 03:11 AM · androidbuttonspritetouchscreen

How to move an image by tocuhing a button (using UI) [Android game]

Hi! I am fairly new using unity. In this short time that I've been using this software, I have been learning a lot. But, there are several primordial things that I can't understand yet. Im trying to make an android game in 2d and I just want to move an object to an static position by pressing a button (below this description I made an ugly scheme explaining my purpose).

I learned how to set sprites/images in the screen using the UI Canvas tool (how to set the position, how to set the size...). I understand too, how the default methods works (start and Upload). But I can't realize this things: -How to make a function that will execute at the moment that the button is touched (I suppose that we can't use the Upload function because it will not occurs always). -How can I make a function (from a script that belongs to this button) move another object.

I made a script for the object that I want to move that has a new function where I change the position of the object itself (something like transform.position=new vector3(-200,0,0); a static position... but I dont know how to call this function from the "button event" and if im making it in the correct way).

alt text

In this scheme you can see my purpose. After touching the "aButton" the black object (it can be a sprite or anything) must move to (-200,0) position.


Thanks for reading my question and sorry for my bad english.

expl.png (3.0 kB)
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 Kastenessen · Jan 15, 2015 at 05:13 AM

Well, all I do is have a 2d collider on the button and use a raycast check and a on mouse button down click to activate a static bool that is accessable by the thing you want to move.

So once the bool is down it will move. Put the bool in the update function and make another bool also to switch its movement bool off and on, so you can stop it from moving again when you want to.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GoogleVR Sprite2D and Buttons Flickering/Glitch and FPS Canvas on one Screen 0 Answers

I can't change the sprite using the Touch class 0 Answers

Problem with touch button (when moved) 2 Answers

how use specific for mobile button when we have 3 ? 1 Answer

I am making android fps and my raycast shooting button don't work. What I should do? 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