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 Xeong-Hu · Mar 24, 2014 at 03:30 PM · movementifmovetowards

How to make an event happen when my Gameobject is moving

I'm making a card game

What I'm trying to do is make my summon function button de-active while my Card is moving towards the spot.

I tried doing an if statement but my script kept giving me an error.

     if (Summon == true && hit.collider.tag == "Card")
         
     {
         var step = speed * Time.deltaTime;
         selectedCard.transform.position = Vector3.MoveTowards(selectedCard.transform.position, target1.position, step);
        {print("I have been Summoned!");}
     }

Is there a way I can put movetowards in an if statement? If not. Can you please tell me how to make my game detect an Objects movement and apply it's effect?

I'd appreciate it.

Comment
Add comment · Show 7
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 robertbu · Mar 24, 2014 at 03:33 PM 0
Share

The typical solution is to check to see if the object is at the end position each frame:

 if (selectedCard.transform.position == target1.position)

This won't be true while the object is moving. Note this works fine for $$anonymous$$oveTowards(), but don't use it for Lerp() using a similar format. To reverse the logic, use '!='.

avatar image Xeong-Hu · Mar 24, 2014 at 06:39 PM 0
Share

Wow dude you answered that quickly! Lol $$anonymous$$an you're awesome btw i'll take your advice for sure.

I'm trying out this code now.

avatar image Xeong-Hu · Mar 24, 2014 at 09:04 PM 0
Share

Alright cool I was thinking about that and it did work but. While it is moving. Summon = true so if the player clicks on another card while summon = true that card would also move lol. It'll be like double summoning cheat code or some crap and that's a problem. So I want to do this.

If Summon = true, $$anonymous$$y Onmouse down is unable to click.

Basically while the object is moving the player is unable to do any clicking functions.

I tried searching it but.. I don't think I got what I was looking for, can please help me out with that?

But since it's not detecting the movement. I really mean how can I make my Onmouse Click unable to be active as long as Summon = True?

I'm trying to find out......

avatar image getyour411 · Mar 24, 2014 at 10:02 PM 0
Share
 On$$anonymous$$ouseclick()
 if(Summon)
 return;
 else
 // do stuff
avatar image Xeong-Hu · Mar 24, 2014 at 10:41 PM 0
Share

Alright so I tried that out and this what I came up with.

 function On$$anonymous$$ouseDown(){
 
 if(Summon == true){
 return null;
 print ("Hmm");}
 else{
 // do stuff
     }
 }


But it's still not working.

I changed On$$anonymous$$ouseclick to On$$anonymous$$ouseDown cause I couldn't find that as a script in the Script reference.

and I did a print but I don't see it appearing.

Show more comments

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

Convert WASD to local rotation 1 Answer

MoveTowards inside Coroutine 2 Answers

how to stop something from following in the y axis 1 Answer

Moving 2D sprite along a path 0 Answers

Moving only if straight path dijkstra 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