- Home /
Duplicate Question
How to change position of a 2d game object through another?
I'm trying to push other game objects whenever it hits my bat,how can I call other game objects through the script attached to my bat and push them forward relative to whether the bat is to the left or to the right of the object?
One way i thought of is to make a function in the other script that will make it bump left after collision but I don't know how to compare the x position of my bat to the enemy's x position.
if (this.transform.position.x < gameObject.Bugbot.position.x)
{
col.gameObject.GetComponent<Bugbot>().bumpLeft();
}
How do I interact with Script B from Script A is probably the most asked question of all times; there are literally thousands of examples, video/tutorials, code snippets, etc. - please search UA/Google.
$$anonymous$$oving things in Unity could possibly be the second most frequently asked; are you wanting to use Physics, Transform.Translate, etc? A quick search on UA/Google for any reasonable keywords found in your question will return many results.
If you read a little, research the doc, try some code and it does not work, ask a new specific question.
Follow this Question
Related Questions
Position and rotation of a game object acting wired 0 Answers
how can I display a variable as a GUIText 5 Answers
Help touch button 1 Answer
Get enemy position in script 1 Answer
Destroy all GameObjects EXCEPT some... 2 Answers