I’m creating a simple 2D scroll game (like flappy bird, character goes all the way to the right and the background & obstacles are automatically and repeatedly generated)
I created three backgrounds, left, middle and right, and place them next to each other. A script called scrolling is added to each background. The script goes:
public GameObject next
public int distance
void OnTriggerEnter2D(Collider2D c){
next.transform.Translate(new Vector3(distance,0,0));
Debug.Log("enter");
}
“left” acts as next for right, right for middle, and middle for left, so they pave the road ahead in turn on and on.
A Physics2D trigger is placed on the background (which is a rectanglular sprite), as well as a circle collider on the main character. However, when the character enters…nothing at all happened. Even the log did not show. Does anyone know why this happened?
Or, after I rethought about it, would the reason be that I simply “translate” the main character to make it move in one direction? Since I want him to move uniformly in x direction. But would this make him a kinematic object, so that the collision with the trigger doesn’t count?