I have created a script that removes gaps between moving platforms on my 2D sidescroller game by checking for another platform infront of the platform with the script and then aligning itself to this platform.

The script works perfectly as planned in the unity editor and on PC standalone, but when I put the game onto my android phone, there are gaps and it runs as if the script doesn’t even exist.

There are also no errors whatsoever on PC or android

Here is my script:

using UnityEngine;
using System.Collections;

public class CheckPos : MonoBehaviour {
	
	public Transform _alignTo = null;
	public bool _align = false;

	Transform myTransform;

	void Start ()
	{
		myTransform = transform;
	}

	void Update()
	{
		myTransform.position = transform.parent.position;
	}

	void OnTriggerEnter(Collider other)
	{
		if(other.tag == "Environment" && _align == true){
			_alignTo = other.transform;
			Align();
		} 
	}

	void OnTriggerExit ()
	{
		_alignTo = null;
	}

	public void Align()
	{
		//yield return new WaitForSeconds(0.1f);
		myTransform.parent.position = _alignTo.transform.position + new Vector3(1f, 0f, 0f);
	}
}

UPDATE:

I have built a standalone PC version of the game with better debugging. It seems I have the same problem as with android on pc standalone as well.

Unfortunately the errors are fairly vague so I can’t pinpoint the problem… any ideas?

GameObject has undefined tag, means that you’ve previously assigned a tag to an object, you are now querying that tag, but it was deleted from the Tags list in Project Settings > Tags. If it’s still there, check the spelling or maybe recreate it to see if that fixes it. All this shouldn’t make any difference between platforms.

For anyone who had a similar issue:

What happened to me was that I deleted some tags I no longer needed. Then In the editor, the game worked perfectly, but in the build it did not. This is because I ignored the the Unity editor message located right at the bottom of the Tags editor saying something along the lines: if you delete them, you need to restart unity in order for the removed tags to be fully removed.

This will cause errors in your builds if you don’t restart unity and fully remove tags.

try

other.gameObject.CompareTag("Environment")

instead of

other.tag == "Environment"

Hope it helps.