I've followed 10+ tutorials on setting up basic C# code to allow a player gameObject to stick to a moving platform (even followed the code verbatim) and nothing works. I added some debug print statements to the console to see when the moving platform detects a collision/trigger with the player gameObject and not even the debug print statements are getting triggered.
I'm using the Unity ThirdPersonController asset with the default "Playground" scene loaded.
I created a primitive cube shaped like a platform using the default Box collider. I DID NOT add rigidbody component since this makes the platform wobble when the player bumps into it. Then I added a script component to the platform as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform_Stick : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter(Collision collision)
{
Debug.Log("Hello Collision");
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("Hello Trigger");
other.transform.parent = transform;
}
private void OnTriggerExit(Collider other)
{
Debug.Log("Goodbye Trigger");
other.transform.parent = null;
}
}
I used the animator to move the platform left and right. When I jump onto the platform, none of the Debug statements print to console. Does this mean collisions aren't being detected? I also added a second box collider that extends slightly above the platform and checked the box for "Is Trigger".
I'm new to Unity and don't understand why nothing I try is working despite copying tutorials online step by step.
Please help!