I’m trying to create a game where as a player you need to dodge objects which are moving downwards. I have objects moving on the right and left side of the screen. By default my prefab is created to spawn on the right side and face right. And I need to mirror this prefab onto the left side correctly.
I instantiate prefabs and apply force to them to move downwards:
Please, check the documentation for the Translate method. This method also accepts a second parameter, which determines the space relative to which the movement will occur. By default, this space is the object’s own space, but if you want to move relative to the world (global space), you need to set this parameter to Space.World.
GameObjects have all the same GetComponent methods that components do. In fact, Component.GetComponent just calls GameObject.GetComponent and so on.
It would actually return a component instance if one exists. You can reference child game objects of prefabs; you can even serialize references to them! (just not via vanilla inspector means)
But yes they should be operating on the instance and not the prefab in this instance.
For me, Unity throws an exception at runtime: ArgumentException: GetComponent requires that the requested component ‘GameObject’ derives from MonoBehaviour or Component or is an interface.