Hello so as you can see in the video im making a game where when you jump the tiles switch. when you jump the box collider should enable and disable but the problem is that in the build it doesnt do that it only disables and enables the box collider.
In general, DO NOT use Find-like or GetComponent/AddComponent-like methods unless there truly is no other way, eg, dynamic runtime discovery of arbitrary objects. These mechanisms are for extremely-advanced use ONLY. If something is built into your scene or prefab, make a script and drag the reference(s) in. That will let you experience the highest rate of The Unity Way™ success of accessing things in your game.
“Stop playing ‘Where’s GameWaldo’ and drag it in already!”
Hello, I have removed all the GameObject.Find() and GetComponent<>() functions but the problem still continues.
I have tried many things such as deleting the library folder, thank you for your help.
Have you looked at the player.log to see if any errors are firing in a build?
Nonetheless the swapping should probably be moved onto a new component for the each of the red and blue grid tilemaps. Perhaps give a way for them to hook into your player to know when they jump.
Most straightforward way would be to just have a global delegate for when your player jumps:
public static event System.Action OnPlayerJumped;
When the player jumps, you can invoke the delegate:
if (Input.GetButtonDown("Jump"))
{
OnPlayerJumped?.Invoke();
}
Then you can make a component for your tilemap(s) that listen to it:
public class TileMapSwapper : Monobehaviour
{
private void Awake()
{
Movement.OnPlayerJumped += HandleOnPlayerJumped;
}
private void OnDestroy()
{
// remember to unsubscribe!
Movement.OnPlayerJumped -= HandleOnPlayerJumped;
}
private void HandleOnPlayerJumped()
{
// swap tiles in tilemap
}
}
I tried this and unfortunately it still doesnt work in the build, I checked the Player.log and couldnt find anything. Could it be a problem in the rendering?