I am currently trying to implement an obstacle of rotating planks for a player to try and navigate across. I would like the player to attach to the plank as it rotates rather than the player having to move with the plank to stay on. The code I am trying to use I am told should work but is not. Any ideas?
public class PlayerScript : MonoBehaviour {
public Collision collision;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag=="bridge")
{
transform.parent=collision.transform;
}
}
void OnCollisionExit(Collision collisionInfo)
{
if (collisionInfo.gameObject.tag=="bridge")
{
collision.transform.DetachChildren();
}
}
}