- Home /
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.
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 '!='.
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.
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......
On$$anonymous$$ouseclick()
if(Summon)
return;
else
// do stuff
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.
Your answer

Follow this Question
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